Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-61869

Infer rendering of templatables with no render method

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 3.4
    • Fix Version/s: 3.5
    • Component/s: HTML and CSS
    • Labels:
    • Testing Instructions:
      Hide

      Core component

      • Use the Clean theme
      • Visit a course page and turn editing on
      • Verify that action menus are displayed correctly.
      • Edit the file lib/ouputrenderers.php - delete the method core_renderer::render_action_menu()
      • Reload the course page, verify that the action menus are still displayed - they are now being rendered using the new template inference.
      • Switch to Boost theme
      • Visit the course page again
      • Verify that the action menus are displayed correctly - they are using Boost's overridden render_action_menu() method even though the core one isn't defined.

      Namespaced plugin component

      • Create a forum and visit the main page
      • Click "Search forums" to view the advanced search page, verify that the form is displayed correctly.
      • Edit the file mod/forum/renderer.php and delete the method mod_forum_renderer::render_big_search_form()
      • Reload the search page, verify that the form still displays correctly - it is now being rendered using template inference.
      Show
      Core component Use the Clean theme Visit a course page and turn editing on Verify that action menus are displayed correctly. Edit the file lib/ouputrenderers.php - delete the method core_renderer::render_action_menu() Reload the course page, verify that the action menus are still displayed - they are now being rendered using the new template inference. Switch to Boost theme Visit the course page again Verify that the action menus are displayed correctly - they are using Boost's overridden render_action_menu() method even though the core one isn't defined. Namespaced plugin component Create a forum and visit the main page Click "Search forums" to view the advanced search page, verify that the form is displayed correctly. Edit the file mod/forum/renderer.php and delete the method mod_forum_renderer::render_big_search_form() Reload the search page, verify that the form still displays correctly - it is now being rendered using template inference.
    • Affected Branches:
      MOODLE_34_STABLE
    • Fixed Branches:
      MOODLE_35_STABLE
    • Pull Master Branch:
      MDL-61869_master

      Description

      With reference to my proposal here: https://moodle.org/mod/forum/discuss.php?d=368403
      Currently in simplest use case of templates, we're required to create a two-line render method for each templatable object, which calls export_for_template and passes the result into render_from_template.

      To make developers' lives a little easier and cut down on boilerplate code, we could assume that if there's no render_thing() method for their templatable, they want to do this simple case using a template with the same name as their object.

      This shouldn't affect existing code at all - the render_thing() method should have precedence over the inferred template rendering, and themes should still override templates and renderer functions, even if the render_thing() method was not defined in the component's renderer.

      Specifics:

      • Passing a templateable object of class my_component\mywidget to render() will check if the render_mywidget() method exists. If not, it will assume that you want to call export_for_template() on the object, and pass the output to render_from_template('my_component/mywidget')
      • If the templatable object is not namespaced, it will assume you want to use the 'core/mywidget' template.
      • If there are sub-namespaces in the class, they will be ignored. The first part of the namespace path will be used as the component name, and the last as the template name, so my_component\output\mywidget will still use the 'my_component/mywidget' template.

        Attachments

          Activity

            People

            • Votes:
              10 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Fix Release Date:
                17/May/18