Moodle PHP Documentation 4.5
Moodle 4.5dev (Build: 20240606) (d3ae1391abe)
Mustache_Template Class Reference
Inheritance diagram for Mustache_Template:
s

Public Member Functions

 __construct (Mustache_Engine $mustache)
 Mustache Template constructor.
 
 __invoke ($context=array())
 Mustache Template instances can be treated as a function and rendered by simply calling them.
 
 render ($context=array())
 Render this template given the rendering context.
 
 renderInternal (Mustache_Context $context, $indent='')
 Internal rendering method implemented by Mustache Template concrete subclasses.
 

Protected Member Functions

 isIterable ($value)
 Tests whether a value should be iterated over (e.g.
 
 prepareContextStack ($context=null)
 Helper method to prepare the Context stack.
 
 resolveValue ($value, Mustache_Context $context)
 Resolve a context value.
 

Protected Attributes

Mustache_Engine $mustache
 
bool $strictCallables = false
 

Constructor & Destructor Documentation

◆ __construct()

Mustache_Template::__construct ( Mustache_Engine $mustache)

Mustache Template constructor.

Parameters
Mustache_Engine$mustache

Member Function Documentation

◆ __invoke()

Mustache_Template::__invoke ( $context = array())

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!"
See also
Mustache_Template\render
Parameters
mixed$contextArray or object rendering context (default: array())
Return values
stringRendered template

◆ isIterable()

Mustache_Template::isIterable ( $value)
protected

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'),
);
Parameters
mixed$value
Return values
boolTrue if the value is 'iterable'

◆ prepareContextStack()

Mustache_Template::prepareContextStack ( $context = null)
protected

Helper method to prepare the Context stack.

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

Parameters
mixed$contextOptional first context frame (default: null)
Return values
Mustache_Context

◆ render()

Mustache_Template::render ( $context = array())

Render this template given the rendering context.

Parameters
mixed$contextArray or object rendering context (default: array())
Return values
stringRendered template

◆ renderInternal()

Mustache_Template::renderInternal ( Mustache_Context $context,
$indent = '' )
abstract

Internal rendering method implemented by Mustache Template concrete subclasses.

This is where the magic happens :)

NOTE: This method is not part of the Mustache.php public API.

Parameters
Mustache_Context$context
string$indent(default: '')
Return values
stringRendered template

◆ resolveValue()

Mustache_Template::resolveValue ( $value,
Mustache_Context $context )
protected

Resolve a context value.

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

Parameters
mixed$value
Mustache_Context$context
Return values
string

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