---
title: Template syntax
project: OpenTemplates
version: 1.0
section: guides
language: en
license: MIT
url: https://totaljs.es/docs/opentemplates/1-0/guides/template-syntax/
updated: 2026-11-19T07:56:20.546Z
---

# Template syntax

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

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

## Values

```html
<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`:

```html
{{ value.note | raw }}
```

## Conditions

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

## Loops

```html
<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](../../reference/profiles/) returns it as `model`, so app developers can see which fields a template expects. The block is never part of the output.

```html
<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](../layouts/). Helpers in the layout work in every template of the profile.

```html
<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.

```html
<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>
```
