Mustache Output location - Moodle 3.5+

Mustache Output location - Moodle 3.5+

por Dave Emsley -
Número de respostas: 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



Media de puntuacións: -
En resposta a Dave Emsley

Re: Mustache Output location - Moodle 3.5+

por Mark Sharp -
Imaxe de Core developers Imaxe de Particularly helpful Moodlers Imaxe de 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}}.

Media de puntuacións:Useful (2)
En resposta a Mark Sharp

Re: Mustache Output location - Moodle 3.5+

por 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

En resposta a Dave Emsley

Re: Mustache Output location - Moodle 3.5+

por 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.

En resposta a Dave Emsley

Re: Mustache Output location - Moodle 3.5+

por Richard Oelmann -
Imaxe de Core developers Imaxe de Particularly helpful Moodlers Imaxe de Plugin developers Imaxe de 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.
Media de puntuacións:Useful (1)