TemplateProcessor
A builder-like processor for a simple template engine with three basic features:
Values: replace a placeholder in the template with a value. Values in templates are wrapped by double square brackets:
[[NAME]]
.Conditionals: show or hide fragments of the template code. The fragment in the template must be fenced by
[[if:NAME]]
and[[endif:NAME]]
. An inverted (not) placeholder is fenced by[[if:!NAME]]
and[[endif:!NAME]]
.Iterables: repeat the content in their fragment as many times as the iterable's size, while replacing the placeholder with the current item during each iteration. The fragment in the template must be fenced by
[[for:NAME]]
and[[endfor:NAME]]
, and the iterated value appears like a normal value:[[NAME]]
.
For example, an HTML wrapper may add <html><head>...</head><body>...</body></html>
, with the content injected in body
. An example template resource can be found in resources/render/html-wrapper.html.template
Parameters
text or code of the template
Constructors
Functions
Adds a conditional variable that shows or removes fragments of the template code. The fragment in the template must be fenced by [[if:NAME]]
and [[endif:NAME]]
. An inverted (not) placeholder is also injected and can be accessed via [[if:!NAME]]
.
Adds a reference to a content placeholder in the template code. This is used to inject rendered code in a template.
Creates a copy of this template processor with the same injected properties.
Adds an iterable to replace a placeholder in the template code. The placeholder in the template must be fenced by [[for:NAME]]
and [[endfor:NAME]]
, and the iterated value appears like a normal value: [[NAME]]
.
Adds both a conditional to check if value is not null
, and a value to replace the placeholder with the non-null
value.
Adds a reference to a placeholder in the template code. The placeholder in the template must be wrapped by double square brackets.