General developer forum

Extending/Overriding Core Mustache Templates

 
Picture of Tony Finlay
Extending/Overriding Core Mustache Templates
 

If I extend a core template in my theme (blocks.mustache for example), how can I output theme data inside it? 

I've added the template to: theme_name/templates/core/blocks.mustache and I've tried adding a simple variable with the site name but it outputs no data.

Is there any way of doing this without extending the renderer?

 
Average of ratings: -
Picture of Kathrin Osswald
Re: Extending/Overriding Core Mustache Templates
 

Hi Tony,

in Boost child themes, it's not possible to put mutsache files in a sub directory - even if they are located there within Boost itself.

The child theme calls a function and there you can read following:

[yourserver]/lib/classes/output/mustache_template_finder.php
public static function get_template_filepath($name, $themename = '') {
(...)
107: throw new coding_exception('Templates names must be specified as "componentname/templatename"'
113: throw new coding_exception('Templates cannot be placed in sub directories
}
So you simply have to put it in your own templates folder without any sub directories:

[theme_name]/templates/blocks.mustache

And then call it with render_from_template_function:

return $this->render_from_template('[theme_name]/blocks', $context);


Cheers, Kathrin

 
Average of ratings: Useful (2)
Picture of Richard Oelmann
Re: Extending/Overriding Core Mustache Templates
Group Core developersGroup Particularly helpful MoodlersGroup Plugin developersGroup Testers

You can't.

Besides Katherin's comments above, mustache needs to be fed all the variables its displaying via the context it is sent. So if the variable you want to display isn't already part of the context being sent to your template (I am assuming its not as you said you added a variable to the template), you would have to override the renderer or whatever function or layout file is sending the context to the template.

Richard

 
Average of ratings: Useful (2)
Picture of Kathrin Osswald
Re: Extending/Overriding Core Mustache Templates
 

Hi Richard,

good point. Forgot this aspect.

 
Average of ratings: -
Picture of Tony Finlay
Re: Extending/Overriding Core Mustache Templates
 

Hi Richard/Katherin, thanks for the replies, kind of hoping this wasn't the case.

 
Average of ratings: -