Language functions

HSVT language template functions implement the core features necessary for useful HTML templating.

if(value) & unless(value)

A simple conditional control flow function. If value is truthy, the anonymous block is rendered if it is, otherwise the else block. unless() inverts this logic.

each(value)

Where value is an array-like object, then the anonymous block is rendered once per item in that list with the view set to that item.

within(value)

The view is moved to the value, then the anonymous block is rendered.

If the value is not defined, then nothing is rendered.

switch(value)

Evaluate value as a string, then render the named block with that name. If that block doesn’t exist, render the anonymous block.

do() { }

Render the anonymous block. yield:name() within that block renders the named block to the do() function.

This is useful for things like conditionally adding links around generated HTML.

template:X()

Include another template in the rendered output. The template name, X, is part of the function name.

Templates may be a standard template, or a template defined by the plugin. Where a plugin template is in a subdirectory, the directory names are separated with : characters.

yield() & yield:Y()

When rendering a do() anonymous block, or template which has been included in another using the template:X() function, render a block from the calling function. yield() renders the anonymous block, yield:Y() renders the block named Y.

render(deferred)

Include a deferred render into the current template, created using the deferredRender() function on a Template.

This is intended to prevent you from needing to use unsafeHTML() by giving you a mechanisum to safely include rendered templates.

See Deferred rendering for how to use render().

Use O.isDeferredRender() to check whether an object is a deferred render.

url(…)

Pseudo function with special parsing. See URLs.

concat(…)

Output all the arguments. No whitespace is output between them.

Use to override the automatic space separated values when using lists as attribute values.

scriptTag(…)

Pseudo function for generating <script> tags. The arguments are a URL, as url(), and the resulting URL is output as the src attribute in <script src="..."></script> tag pair.

Script tags are otherwise not allowed in templates, because including JavaScript is too dangerous and should be prohibited by your Content Security Policy.

unsafeHTML(unsafeValue)

Evaluate unsafeValue as a string, then output directly in the template without escaping. A parse error is thrown if it is used outside the text context (eg can’t be used in an attribute value).

The value name, or one of the path elements, must begin with unsafe so that it’s obvious in the code generating the view that the value will be used unsafely.

Try to use render() and deferredRender() instead.

unsafeAttributeValue(unsafeValue)

Override id, class and style attribute restrictions by pretending a value is a literal string. The value is escaped within the attribute.

A parse error is thrown if it is used outside the attribute context.

The value name, or one of the path elements, must begin with unsafe so that it’s obvious in the code generating the view that the value will be used unsafely.

Try to use a data- attribute instead and select on that value in your JavaScript code.