DVE templates are HTML (or any text) with {{ ... }} tags layered on top. There are two core shapes: a {{ ... }} tag that shows a value and a {{#... }} ... {{/... }} tag that wraps a block like a loop or a conditional.
- Variables
- Raw Output
- Comments
- Include
- Layouts: Extend, Block, Slot
- Conditionals
- Loops
- Loop Metadata
- Whitespace Control
A value in double braces is printed and HTML-escaped by default, so user input can never inject markup.
Hello {{ name }}.Triple braces print the value with no escaping. Use it only for HTML you already trust.
{{{ trustedHtml }}}Comments are never rendered.
{{!-- this is removed from the output --}}Pull another template in with {{> path}}. The path is passed to the engine's resolveInclude option.
{{> partials/header.dve}}A page inherits from a layout with {{< path}} ... {{/}}. The layout exposes named placeholders with {{#slot name}}default{{/slot}}, and the child fills them with {{#block name}}...{{/block}}. A slot renders its own default when no block is provided, and a block with no matching slot is rejected as an error.
layouts/main.dve:
<title>{{#slot title}}Untitled{{/slot}}</title>
<main>{{#slot body}}{{/slot}}</main>page.dve:
{{< layouts/main.dve}}
{{#block title}}Home{{/block}}
{{#block body}}<p>Welcome.</p>{{/block}}
{{/}}{{#if}} renders its body when the condition is truthy. {{else if}} and {{else}} are optional. Every {{#if}} must be closed with {{/if}}.
{{#if user?.isAdmin}}
ADMIN
{{else if user?.name}}
USER
{{else}}
GUEST
{{/if}}{{#each}} walks an array. The as name part names the current item, defaulting to item when omitted. An optional {{else}} renders when the array is empty or missing.
{{#each items as item}}
{{ item }},
{{else}}
No items.
{{/each}}Inside an {{#each}} block these helpers are available for free:
@index- current position, starting at 0 (supports arithmetic, e.g.{{ @index + 1 }})@first-trueon the first item@last-trueon the last item@length- total number of items
{{#each items as item}}({{ @index + 1 }}/{{ @length }}) {{ item }} {{/each}}A ~ next to the braces trims adjacent whitespace, which keeps generated HTML tidy.
{{#each items as item~}}
{{ item }}
{{~/each}}Note
See Expressions for everything that can go inside a {{ ... }} tag.