Mustache Output location - Moodle 3.5+

Mustache Output location - Moodle 3.5+

by Dave Emsley -
Number of replies: 6

Hi there,  apologies as I seem to have a blind spot where mustache is concerned.

In the file:  theme/boost/templates/navbar.mustache  there is a line which says:

                {{{ output.user_menu }}}

Where does it find the content from?  I had assumed the theme renderer but I cannot find it anywhere.


Best Regards

Dave



Average of ratings: -
In reply to Dave Emsley

Re: Mustache Output location - Moodle 3.5+

by Mark Sharp -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Any public functions in the output renderer can be a mustache tag used with {{ output.functionname }}. In your theme you can override the output renderer, and change the function, like user_menu. You can also add your own functions e.g. function mywhizzbangfunction() -> {{output.mywhizzbangfunction}}.

Average of ratings: Useful (2)
In reply to Mark Sharp

Re: Mustache Output location - Moodle 3.5+

by Dave Emsley -
Brilliant, thanks Rex and Mark this was really useful. Although where do I put my theme renderer? Is theme_name/classes/output/core_renderer.php too obvious?

At present I'm thinking:

class theme_mythemename_core_renderer extends \core_renderer {
    public function user_menu($user = null, $withlinks = null) {
        global $USER, $CFG;
        require_once($CFG->dirroot . '/user/lib.php');
        if (is_null($user)) {
$user = $USER; } ... ... return html_writer::div( $this->render($am), $usermenuclasses ); } //End of function } //End of class

Is this the correct way to do this or have I missed something else?
Cheers
Dave

In reply to Dave Emsley

Re: Mustache Output location - Moodle 3.5+

by Dave Emsley -

...or just replicate the bits I need out of Boost theme....

namespace theme_mythemename\output;
defined('MOODLE_INTERNAL') || die();
class core_renderer extends \core_renderer {
...
...
}



Many thanks again for the help and support.

In reply to Dave Emsley

Re: Mustache Output location - Moodle 3.5+

by Richard Oelmann -
Picture of Core developers Picture of Plugin developers Picture of Testers
Take a look at a few of the themes that already do something similar Dave - for example you may actually be needing to override the renderer in Boost as the core one may already have been overridden, depending on your parent theme
There are many examples in existing themes, such as https://gitlab.com/ro-mdl-themes/moodle-theme_handlebar/blob/master/classes/output/core_renderer.php and you'd certainly also find examples in some of Gareth's themes like Essential or Shoelace and in Adaptable or Moove and others I'm sure smile

Hope that helps.
Average of ratings: Useful (1)