\Charcoal\View\MustacheMustacheEngine

Mustache view rendering engine.

View Engines are comprised of 2 things:

  • A template loader, wich is a LoaderInterfaceObject
    • Set with set_loader() / Get with loader()
    • Provides loadtemplate() method
  • A render() method, which takes a $template and a $context arguments

Engines implements the LoggerAwareInterface. A logger can be accessed with the logger() method.

Summary

Methods
Properties
Constants
type()
__construct()
loadTemplate()
render()
renderTemplate()
setHelpers()
mergeHelpers()
addHelper()
helpers()
No public properties found
No constants found
loader()
mustache()
createMustache()
No protected properties found
N/A
setLoader()
$loader
$helpers
$mustache
N/A

Properties

$helpers

$helpers : array

A collection of helpers.

Type

array

$mustache

$mustache : \Mustache_Engine

The renderering framework.

Type

\Mustache_Engine

Methods

type()

type() : string

Returns

string

__construct()

__construct(array  $data) 

Build the Mustache Engine with an array of dependencies.

Required parameters:

  • logger a PSR-3 logger

Optional parameters:

  • loader a Loader object

Parameters

array $data

Engine dependencie.

loadTemplate()

loadTemplate(string  $templateIdent) : string

Delegates template loading to the engine's Loader object.

Parameters

string $templateIdent

The template identifier to load.

Returns

string —

The template string, loaded from identifier.

render()

render(string  $templateIdent, mixed  $context) : string

Load a template (from identifier) and render it.

Parameters

string $templateIdent

The template identifier to load and render.

mixed $context

The rendering context.

Returns

string —

The rendered template string.

renderTemplate()

renderTemplate(string  $templateString, mixed  $context) : string

Render a template (from string).

Parameters

string $templateString

The template string to render.

mixed $context

The rendering context.

Returns

string —

The rendered template string.

setHelpers()

setHelpers(array|\Traversable|\Charcoal\View\Mustache\HelpersInterface  $helpers) : \Charcoal\View\Mustache\MustacheEngine

Set the engine's helpers.

Parameters

array|\Traversable|\Charcoal\View\Mustache\HelpersInterface $helpers

Mustache helpers.

Throws

\InvalidArgumentException

If the given helper(s) are invalid.

Returns

\Charcoal\View\Mustache\MustacheEngine

Chainable

mergeHelpers()

mergeHelpers(array|\Traversable|\Charcoal\View\Mustache\HelpersInterface  $helpers) : \Charcoal\View\Mustache\MustacheEngine

Merge (replacing or adding) the engine's helpers.

Parameters

array|\Traversable|\Charcoal\View\Mustache\HelpersInterface $helpers

Mustache helpers.

Throws

\InvalidArgumentException

If the given helper(s) are invalid.

Returns

\Charcoal\View\Mustache\MustacheEngine

Chainable

addHelper()

addHelper(string  $name, mixed  $helper) : \Charcoal\View\Mustache\MustacheEngine

Add a helper.

Parameters

string $name

The tag name.

mixed $helper

The tag value.

Returns

\Charcoal\View\Mustache\MustacheEngine

Chainable

helpers()

helpers() : array

Retrieve the engine's helpers.

Returns

array

mustache()

mustache() : \Mustache_Engine

Returns

\Mustache_Engine

createMustache()

createMustache() : \Mustache_Engine

Returns

\Mustache_Engine