Moodle PHP Documentation 4.2
Moodle 4.2.8 (Build: 20240610) (2d41ac46f45)
core\output\mustache_template_source_loader Class Reference

Load template source strings. More...

Public Member Functions

 __construct (callable $gettemplatesource=null)
 Constructor that takes a callback to allow the calling code to specify how to retrieve the source for a template name.
 
 load (string $component, string $name, string $themename, bool $includecomments=false)
 Load the template source from the component and template name.
 
 load_with_dependencies (string $templatecomponent, string $templatename, string $themename, bool $includecomments=false, array $seentemplates=[], array $seenstrings=[], string $lang=null)
 Load a template and some of the dependencies that will be needed in order to render the template.
 

Protected Member Functions

 get_string_identifiers (array $tokens, int $start)
 Gets the identifier and component of the string.
 
 scan_template_source_for_dependencies (string $source)
 Scan over a template source string and return a list of dependencies it requires.
 
 strip_template_comments ($templatestr)
 Remove comments from mustache template.
 

Detailed Description

Load template source strings.

License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

Constructor & Destructor Documentation

◆ __construct()

core\output\mustache_template_source_loader::__construct ( callable $gettemplatesource = null)

Constructor that takes a callback to allow the calling code to specify how to retrieve the source for a template name.

If no callback is provided then default to the load from disk implementation.

Parameters
callable | null$gettemplatesourceCallback to load template source by template name

Member Function Documentation

◆ get_string_identifiers()

core\output\mustache_template_source_loader::get_string_identifiers ( array $tokens,
int $start )
protected

Gets the identifier and component of the string.

The string could be defined on one, or multiple lines.

Parameters
array$tokensThe templates token.
int$startThe index of the start of the string token.
Return values
arrayA list of the string identifier and component.

◆ load()

core\output\mustache_template_source_loader::load ( string $component,
string $name,
string $themename,
bool $includecomments = false )

Load the template source from the component and template name.

Parameters
string$componentThe moodle component (e.g. core_message)
string$nameThe template name (e.g. message_drawer)
string$themenameThe theme to load the template for (e.g. boost)
bool$includecommentsIf the comments should be stripped from the source before returning
Return values
stringThe template source

◆ load_with_dependencies()

core\output\mustache_template_source_loader::load_with_dependencies ( string $templatecomponent,
string $templatename,
string $themename,
bool $includecomments = false,
array $seentemplates = [],
array $seenstrings = [],
string $lang = null )

Load a template and some of the dependencies that will be needed in order to render the template.

The current implementation will return all of the templates and all of the strings in each of those templates (excluding string substitutions).

The return format is an array indexed with the dependency type (e.g. templates / strings) then the component (e.g. core_message), and then the id (e.g. message_drawer).

For example:

  • We have 3 templates in core named foo, bar, and baz.
  • foo includes bar and bar includes baz.
  • foo uses the string 'home' from core
  • baz uses the string 'help' from core

If we load the template foo this function would return: [ 'templates' => [ 'core' => [ 'foo' => '... template source ...', 'bar' => '... template source ...', 'baz' => '... template source ...', ] ], 'strings' => [ 'core' => [ 'home' => 'Home', 'help' => 'Help' ] ] ]

Parameters
string$templatecomponentThe moodle component (e.g. core_message)
string$templatenameThe template name (e.g. message_drawer)
string$themenameThe theme to load the template for (e.g. boost)
bool$includecommentsIf the comments should be stripped from the source before returning
array$seentemplatesList of templates already processed / to be skipped.
array$seenstringsList of strings already processed / to be skipped.
string | null$langmoodle translation language, null means use current.
Return values
array

◆ scan_template_source_for_dependencies()

core\output\mustache_template_source_loader::scan_template_source_for_dependencies ( string $source)
protected

Scan over a template source string and return a list of dependencies it requires.

At the moment the list will only include other templates and strings.

The return format is an array indexed with the dependency type (e.g. templates / strings) then the component (e.g. core_message) with it's value being an array of the items required in that component.

For example: If we have a template foo that includes 2 templates, bar and baz, and also 2 strings 'home' and 'help' from the core component then the return value would look like:

[ 'templates' => [ 'core' => ['foo', 'bar', 'baz'] ], 'strings' => [ 'core' => ['home', 'help'] ] ]

Parameters
string$sourceThe template source
Return values
array

◆ strip_template_comments()

core\output\mustache_template_source_loader::strip_template_comments ( $templatestr)
protected

Remove comments from mustache template.

Parameters
string$templatestr
Return values
string

The documentation for this class was generated from the following file: