Moodle mod template with mustache

Moodle mod template with mustache

by Christos Savva -
Number of replies: 5

Hello is there any moodle mod starting point code template using mustache, like the one below?


https://github.com/moodlehq/moodle-mod_newmodule


If yes, could you please give me the link, if no are there any plans to create something?


Thanks in advance

Christos

Average of ratings: -
In reply to Christos Savva

Re: Moodle mod template with mustache

by Hittesh Ahuja -

Just search the Moodle code base for moustache braces .. you'll find loads.. for example https://github.com/moodle/moodle/blob/06e3b6d8bab42b8e56d169d006f31f4a15684830/theme/boost/templates/core_form/element-button.mustache

In reply to Hittesh Ahuja

Re: Moodle mod template with mustache

by Christos Savva -

Thanks for the reply.


The problem I wanted to solve is: what is the best filestructure of a potential new moodle plugin using mustache.


When I checked the block_myoverview for example I can see that there is a folder called classes and a file called renderer.php which calls


return $this->render_from_template('block_myoverview/main', $main->export_for_template($this));


That's why I asked for a skeleton plugin using mustache. If there is no skeleton plugin, are there any guides on how to develop a plugin using mustache?

In reply to Christos Savva

Re: Moodle mod template with mustache

by David Mudrák -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Plugins guardians Picture of Testers Picture of Translators

are there any guides on how to develop a plugin using mustache?

I assume you are aware of https://docs.moodle.org/dev/Templates

Mustache templates should be seen as an additional layer on top of "legacy" Moodle rendering machinery. Or better, as an alternative to generating the HTML.

Your plugin should still implement its renderer. Just instead of having the HTML generated via calls like $this->output->heading() or html_writer::div() and friends, you actually delegate HTML generating to Mustache templates.