Template

Produces contents of file, replacing placeholders with contextual information.

What it does

When a changed Template file is available, it will be cached in memory and split up at the placeholders it contains, if any.

When this Service is hit, the cached template will be written to the nearest OutgoingInteraction, replacing placeholders with information from context. Missing information may be acquired from underlying branches with names that match the placeholder names.

How it works

Example code below is a redacted snippet from the Wiki-software you're using right now. The SQL query provides with title, summary and content information.

Contents of "template.html":

<h1>{% title %}</h1>
<p class="summary">
{% summary %}
</p>
{% content %}

Contents of CLON-file:

{
    instances = {
        begin = SQL(f"queries/GetArticleBody.sql",
            params = ["url"], credset = "wiki", 
            defaults = { url = "main" }
        ) {
            none_branch = StubService();
            single_branch = Return("view") {
                default_branch = Template(f"templates/template.html");
            };
        };
    };
}

Settings

defaultf"path.html"Path to template file, optionally containing {% placeholders %}
templatefilef"path.html"Same as default parameter
checkfortemplateupdatestrue/falseReloads template file when the timestamp on it has changed. Set to 'true' by default.
contextfirsttrue/falseWhen set to true, will check in pre-existing context first, for placeholder fillers. Otherwise, branches are triggered by placeholders
forwardfail"filler string"When a placeholder-triggered branch fails, the text set here will fill the placeholder instead. Defaults to an empty string.
backwardfail"filler string"Same as forwardfail, but for missing contextual information instead

Branches

_branch-name trigger
any name that has been used in a {% placeholder %}Template write cursor arrived at placeholder with this name