Spanish Total.js
English
Documentation For AI agents
Contents

Template syntax

Write values, conditions, loops, a sample model and helpers in a template.

.md GitHub
On this page

Templates are HTML with Tangular tags in double curly braces. The data your app sends is available as value.

Values

<h1>Invoice {{ value.number }}</h1>
<p>Customer: <b>{{ value.customer }}</b></p>

Values are HTML-encoded. To write a value that already contains HTML, add | raw:

{{ value.note | raw }}

Conditions

{{ if value.paid }}
    <p>Paid, thank you.</p>
{{ else }}
    <p>Please pay within 14 days.</p>
{{ fi }}

Loops

<table>
    {{ foreach item in value.items }}
    <tr><td>{{ item.name }}</td><td>{{ item.price | amount }}</td></tr>
    {{ end }}
</table>

The sample model

Put a <script type="text/json"> block with JSON at the end of the template. The editor preview uses it as value, and the profile list returns it as model, so app developers can see which fields a template expects. The block is never part of the output.

<script type="text/json">
    {
        "number": "2026-001",
        "customer": "Jane Doe",
        "items": [
            { "name": "Website design", "price": 1200 },
            { "name": "Hosting (1 year)", "price": 240 }
        ],
        "total": 1440
    }
</script>

Helpers

A helper changes a value before it is written. Define helpers in a plain <script> block, either in the template or in the layout. Helpers in the layout work in every template of the profile.

<div style="padding:20px">
    Hello {{ value.name | uppercase }}!
</div>

<script>
    Thelpers.uppercase = function(val) {
        return val ? val.toUpperCase() : '';
    };
</script>

With the data {"name":"Jane Doe"} this renders Hello JANE DOE!. The <script> block is removed from the output.

Helpers run on the OpenTemplates server when a template is rendered. Write them yourself or take them only from people you trust.

A complete example

This is the demo/invoice template from the screenshots. The amount helper comes from the layout of its profile.

<div style="padding:40px">
    <h1>Invoice {{ value.number }}</h1>
    <p>Customer: <b>{{ value.customer }}</b></p>
    <table style="width:100%;border-collapse:collapse">
        {{ foreach item in value.items }}
        <tr><td style="padding:5px 0">{{ item.name }}</td><td style="text-align:right">{{ item.price | amount }}</td></tr>
        {{ end }}
    </table>
    <p style="text-align:right">Total: <b>{{ value.total | amount }}</b></p>
</div>
Made in Europe