Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 310 and 402] [Versions 310 and 403]

Load template source strings.

Copyright: 2018 Ryan Wyllie <ryan@moodle.com>
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 384 lines (15 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

mustache_template_source_loader:: (6 methods):
  __construct()
  strip_template_comments()
  load()
  load_with_dependencies()
  scan_template_source_for_dependencies()
  get_string_identifiers()


Class: mustache_template_source_loader  - X-Ref

Load template source strings.

__construct(callable $gettemplatesource = null)   X-Ref
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.

param: callable|null $gettemplatesource Callback to load template source by template name

strip_template_comments($templatestr)   X-Ref
Remove comments from mustache template.

param: string $templatestr
return: string

load(string $component,string $name,string $themename,bool $includecomments = false)   X-Ref
Load the template source from the component and template name.

param: string $component The moodle component (e.g. core_message)
param: string $name The template name (e.g. message_drawer)
param: string $themename The theme to load the template for (e.g. boost)
param: bool $includecomments If the comments should be stripped from the source before returning
return: string The template source

load_with_dependencies(string $templatecomponent,string $templatename,string $themename,bool $includecomments = false,array $seentemplates = [],array $seenstrings = [],string $lang = null)   X-Ref
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'
]
]
]

param: string $templatecomponent The moodle component (e.g. core_message)
param: string $templatename The template name (e.g. message_drawer)
param: string $themename The theme to load the template for (e.g. boost)
param: bool $includecomments If the comments should be stripped from the source before returning
param: array $seentemplates List of templates already processed / to be skipped.
param: array $seenstrings List of strings already processed / to be skipped.
param: string|null $lang moodle translation language, null means use current.
return: array

scan_template_source_for_dependencies(string $source)   X-Ref
No description

get_string_identifiers(array $tokens, int $start)   X-Ref
Gets the identifier and component of the string.

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

param: array $tokens The templates token.
param: int $start The index of the start of the string token.
return: array A list of the string identifier and component.