Download the PHP package xp-forge/mustache without Composer
On this page you can find all versions of the php package xp-forge/mustache. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download xp-forge/mustache
More information about xp-forge/mustache
Files in xp-forge/mustache
Package mustache
Short Description The Mustache template language implemented for the XP Framework
License BSD-3-Clause
Homepage http://xp-framework.net/
Informations about the package mustache
Mustache
The mustache template language implemented for the XP Framework.
Introduction
Read the excellent mustache man-page for a start.
Features supported
This implementation supports all standard features of the current specification:
- Interpolation:
{{var}}
({{&var}}
and triple mustaches for unescaped) and the dot-notation. By default misses will be replaced by empty strings. - Comments:
{{! comment }}
. Comments will appear in the parse tree but of course will be excluded when rendering. - Delimiters:
{{=@ @=}}
will change the starting and ending delimiter to the@
sign. Arbitrary length delimiters are supported. - Sections:
{{#section}}
as well as inverted sections:{{^section}}
are supported. - Partials:
{{> partial}}
will load a template calledpartial.mustache
from the template loader. - Implicit iterators: Written as
{{.}}
, the current loop value will be selected.
The optional lambdas module as well as the parent context extension (../name
) are also supported.
Lambdas
If the value is a closure, it will be invoked and the raw text (no interpolations will have been performed!) will be passed to it:
Template
Data
Output
Extended usage
The $text
parameter passed is actually a com.github.mustache.Node
instance but may be treated as text as it overloads the string cast. In order to work with it, the node's evaluate()
method can be called with the com.github.mustache.Context
instance given as the second argument:
Template loading
Per default, templates are loaded from the current working directory. This can be changed by passing a template loader instance to the engine:
This will load the template stored in the file templates/hello.mustache
. This template loader will also be used for partials.
Templates can also be loaded from the class loader, use the com.github.mustache.ResourcesIn
and pass it a class loader instance (e.g. ClassLoader::getDefault()
to search in all class paths) for this purpose.
Compiled templates
If you wish to apply variables to a template more than once, you can speed that process up by precompiling templates and using them later on:
Helpers
Think of helpers as "omnipresent" context. They are added to the engine instance via withHelper()
and will be available in any rendering context invoked on that instance.
Template
Call
Output
Using objects
You can also use instance methods as helpers, e.g.
Spec compliance
Whether this implementation is compliant with the official spec can be tested as follows:
All versions of mustache with dependencies
xp-framework/tokenize Version ^9.0 | ^8.0
php Version >=7.0.0