Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

(no description)

File Size: 180 lines (5 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

Mustache_Template:: (6 methods):
  __construct()
  __invoke()
  render()
  isIterable()
  prepareContextStack()
  resolveValue()


Class: Mustache_Template  - X-Ref

Abstract Mustache Template class.

__construct(Mustache_Engine $mustache)   X-Ref
Mustache Template constructor.

param: Mustache_Engine $mustache

__invoke($context = array()   X-Ref
Mustache Template instances can be treated as a function and rendered by simply calling them.

$m = new Mustache_Engine;
$tpl = $m->loadTemplate('Hello, {{ name }}!');
echo $tpl(array('name' => 'World')); // "Hello, World!"

param: mixed $context Array or object rendering context (default: array())
return: string Rendered template

render($context = array()   X-Ref
Render this template given the rendering context.

param: mixed $context Array or object rendering context (default: array())
return: string Rendered template

isIterable($value)   X-Ref
Tests whether a value should be iterated over (e.g. in a section context).

In most languages there are two distinct array types: list and hash (or whatever you want to call them). Lists
should be iterated, hashes should be treated as objects. Mustache follows this paradigm for Ruby, Javascript,
Java, Python, etc.

PHP, however, treats lists and hashes as one primitive type: array. So Mustache.php needs a way to distinguish
between between a list of things (numeric, normalized array) and a set of variables to be used as section context
(associative array). In other words, this will be iterated over:

$items = array(
array('name' => 'foo'),
array('name' => 'bar'),
array('name' => 'baz'),
);

... but this will be used as a section context block:

$items = array(
1        => array('name' => 'foo'),
'banana' => array('name' => 'bar'),
42       => array('name' => 'baz'),
);

param: mixed $value
return: bool True if the value is 'iterable'

prepareContextStack($context = null)   X-Ref
Helper method to prepare the Context stack.

Adds the Mustache HelperCollection to the stack's top context frame if helpers are present.

param: mixed $context Optional first context frame (default: null)
return: Mustache_Context

resolveValue($value, Mustache_Context $context)   X-Ref
Resolve a context value.

Invoke the value if it is callable, otherwise return the value.

param: mixed            $value
param: Mustache_Context $context
return: string