TEMPLATE(7)

NAME
template - templating language

DESCRIPTION
template is a language used to define programs that output data in some way. These programs are called “templates”. A template file is assumed to be compiled using the template(1) utility into C code, to be further compiled as part of a bigger application. The language itself is format-agnostic and can thus be used to produce various type of outputs.

There are two special sequences:

{{ ... }}
    used for template special syntax.

{! ... !}
    used to include literal C code. This is the only special syntax permitted as top-level, except for block definition and includes.

The basic unit of a template file is the block. Each block is turned into a C function that output its content via some provided functions. Here's an example of a block:

    {{ define tp_base(struct template *tp, const char *title) }}
    <!doctype html>
    <html>
    	<head>
    		<title>{{ title }}</title>
    	</head>
    	<body>
    		{{ render tp->tp_body(tp) }}
    	</body>
    </html>
    {{ end }}

  SPECIAL SYNTAX
This section is a reference for all the special syntaxes supported.

{{ include file }}
    Include additional template files.

{{ define name(arguments ...) }} body {{ end }}
    Defines the block name with the given arguments. body will be outputted as-is via the provided functions (i.e. is still escaped eventually) and can contain all the special syntaxes documented here except include and define.

{{ render expression() }}
    Executes expression() and terminate the template if it returns -1. It's used to render (call) another template.

{{ printf fmt, arguments ... }}
    Outputs the string that would be produced by calling printf(3) with the given fmt format string and the given arguments.

{{ if expr }} ... {{ elseif expr }} ... {{ else }} ... {{ end }}
    Conditional evaluation. elseif can be provided zero or more times, else only zero or one time and always for last.

{{ for ...; ...; ... }} ... {{ end }}
    Looping construct similar to the C for loop.

{{ tailq-foreach var head fieldname }} .. {{ end }}
    Looping construct similar to the queue.h macro TAILQ_FOREACH.

{{ while ... }} ... {{ end }}
    Looping construct similar to the C while loop.

{{ expression | unsafe }}
    Output expression as-is.

{{ expression | urlescape }}
    Output expression escaped in a way that can be made part of an URL.

{{ expression }}
    Output expression with the default escaping.

SEE ALSO
template(1)

AUTHORS
-nosplit The template reference was written by Omar Polo <op@openbsd.org>.