You have been redirected from an outdated version of the article. Below is the content available on this topic. To view the old article click here.

Template Expressions

A Template Expression is a small block of text surrounded by template markers ${}.

The content of the template expression will be evaluated by Structr at runtime, and can be used to display dynamic content inside of Content Elements and many of the attributes of HTML elements.

Example

${project.name}
${capitalize(page.name)}

Details

Structr supports the following expression types inside of a template expression:

See the chapter about StuctrScript for detailed information.

Search results for "Template Expressions"

Template Elements

As defined in the DOM specification, Content Elements must not have child nodes. To be able to mix template expressions and node structures, Structr provides a block-version of Content Elements, the so-called Template Elements (Template icon). Similar to Content Elements, Template Elements support different content types and allow for template expressions. However, in contrast to Content Elements, Template Elements can have children.

Template Expressions

To dynamically generate content during rendering, Structr provides a mechanism for opening a scripting environment within a content element. For these so-called template expressions, Structr uses a syntax similar to the Freemarker Template Language.

Templates

Other than content elements, template elements can have child elements in the DOM tree which makes them very flexible. There are two special template expressions that help organizing the content rendering hierarchy: render() and include_child().

StructrScript

StructrScript is the name of the internal scripting language that can be used in Content or Template nodes, Template Expressions, Show Conditions and HTML attributes. It is a simple interpreted functional scripting language that provides access to Structr’s functionality through a set of functions and keywords. StructrScript has no control structures, it is interpreted like a fully functional language, although some of the Built-In Functions have side effects.

Output on the page

If you use template expressions and built-in functions in a content element, and an error occurs, the error message will be written into the HTML output. If there is an error message on the page, or a usage message for a built-in function, the error is very likely in a dynamic content element in that page.

Edit File

The edit button opens up a dialog to edit the files content. Additionally to editing the raw text of the file, you are presented with three additional configuration parameters namely: Line Wrapping, Replace <a data-id="c535223d2c1e409ebdcbbfcf1479c15f" class="mention">template</a> expressions and Show preview. The line-wrapping option controls how lines are handled that do not fit onto the page. Either a scroll bar at the bottom is provided to navigate the width of the document, or long lines are automatically wrapped at the end border of the dialog box.

The other two parameters, Replace <a data-id="c535223d2c1e409ebdcbbfcf1479c15f" class="mention">template</a> expressions and Show preview, are used to configure so-called dynamic files. Additionally to storing static content, as in the case of the text file above, Structr also allows you to open a scripting context within a file and thus inject dynamically generated content. Such files, containing dynamically generated content, are referred to as dynamic files.

To mark a file as a dynamic file, you have to set the parameter Replace <a data-id="c535223d2c1e409ebdcbbfcf1479c15f" class="mention">template</a> expressions. This instructs Structr to evaluate the file as a script, instead of rendering it’s content statically. If you configure a file to be a dynamic file, the Show preview parameter allows you to render a preview of the dynamically generated content.