Posts made by Urs Hunkler

Picture of Core developers

Damyon - I would like to see the Moodle Mustache implementation as transparent/open as possible.

The implementation should help avoid issues - but it should not try to protect from failure. 

When I make a mistake in my code and somebody reports a bug let's say half a year later I need to fix that bug. When somebody implements a helper only half way (only the PHP part and not the JavaScript part as in your example) and this half implementation becomes an issue sometimes later the helper needs to get fixed. That's how software development works - isn't it?

So the minimum I would like to see is that it will be possible to add helpers in the theme.

Average of ratings: Useful (2)
Picture of Core developers

Great proposal Damyon to use the render_from_template('partial/partialname') call in the renderable instead of a »dynamic partial« helper. With very few changes in the code the helper is not needed any more.

I updated the moodle branch to the latest weekly and committed the theme changes. And I reverted the »dynamic partial« helper commit - it's not needed. You may get the changes form the GitHub repository - or have a look at https://github.com/uhunkler/moodle/commits/master.

Picture of Core developers

Great that you think that my work on the »cleanm« Mustache based theme may be helpful.

I had used the »dynamic partial« helper to be able to make Mustache templates more flexible. Your proposal to »render_from_template« the partial in the wrapper renderable into the »$data->pagecontent« variable should do the same. I'll try that approach and come back with the result.

With the approach to use as few helpers as possible I agree. 

But if I would need a helper for a certain task Mustache is very flexible by making it easy to just add the helper when I need it. The Moodle implementation locks the Mustache instance away and reduces the flexibility Mustache offers. That approach I see as not helpful. I would prefer to be able to access all Mustache features from within Moodle.

Picture of Core developers

Please see my thoughts on helpers in my comment https://moodle.org/mod/forum/discuss.php?d=311119#p1245495.

In my first simple local Mustache test plugin my first approach was to just use the line 

»$OUTPUT->render_from_template('local_mustache_tests/templatename', array('text' => 'Some text to show on the page'));«

But Moodle complained that there is no template »/lib/templates/templatename« (I don't remember the exact path - it just gave me the information that Moodle only looks for templates in the core templates).

When I looked at the Moodle code I saw what you described above - the JavaScript template library browses the system for templates but from PHP only templates included via renderers/renderables are found. I would prefer to be able to use Mustache in Moodle with PHP and JavaScript with all flexibility Mustache offers.

Why is it better to restrict the Mustache template handling in Moodle? 

For core code I see advantages to uses a few common patterns. But as a plugin developer I would prefer to be able to use Mustache's features and don't have Moodle lock Mustache away from the plugin code. Probably it would help already to make the »get_mustache« method public and not »protected«.

If I had access to the Mustache instance it would be easy to tell Mustache about additional template sources.

When I looked at the code again just now while writing this comment I understand the reason why Moodle implements the Mustache template handling in a special restricted way: with this implementation Moodle can guarantee that templates can be overridden in themes. If plugins could add their own templates overriding these plugin templates would be more difficult.

I am not sure if it might be possible to implement a more flexible template integration in Moodle.