1 .\" Copyright (c) 2022 Omar Polo <op@openbsd.org>
3 .\" Permission to use, copy, modify, and distribute this software for any
4 .\" purpose with or without fee is hereby granted, provided that the above
5 .\" copyright notice and this permission notice appear in all copies.
7 .\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8 .\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9 .\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10 .\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11 .\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12 .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13 .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 .Nd templating language
23 is a language used to define programs that output data in some way.
24 These programs are called
28 file is assumed to be compiled using the
30 utility into C code, to be further compiled as part of a bigger
32 The language itself is format-agnostic and can thus be used to produce
33 various type of outputs.
35 There are two special sequences:
37 .It Cm {{ Ar ... Cm }}
41 .It Cm {! Ar ... Cm !}
42 used to include literal C code.
43 This is the only special syntax permitted as top-level, except for block
44 definition and includes.
50 Each block is turned into a C function that output its content via some
52 Here's an example of a block:
53 .Bd -literal -offset indent
54 {{ define tp_base(struct template *tp, const char *title) }}
58 <title>{{ title }}</title>
61 {{ render tp->tp_body(tp) }}
67 This section is a reference for all the special syntaxes supported.
69 .It Cm {{ Ic include Ar file Cm }}
70 Include additional template files.
71 .It Cm {{ Ic define Ar name Ns ( Ar arguments ... ) Cm }} Ar body Cm {{ Ic end Cm }}
77 will be outputted as-is via the provided functions
78 .Pq i.e.\& is still escaped eventually
79 and can contain all the special syntaxes documented here except
83 .It Cm {{ Ic render Ar expression() Cm }}
86 and terminate the template if it returns -1.
87 It's used to render (call) another template.
88 .It Cm {{ Ic printf Ar fmt , Ar arguments ... Cm }}
89 Outputs the string that would be produced by calling
93 format string and the given
95 .It Cm {{ Ic if Ar expr Cm }} Ar ... Cm {{ Ic elseif Ar expr Cm }} Ar ... Cm {{ Ic else Cm }} Ar ... Cm {{ Ic end Cm }}
96 Conditional evaluation.
98 can be provided zero or more times,
100 only zero or one time and always for last.
101 .It Cm {{ Ic for Ar ... ; Ar ... ; Ar ... Cm }} Ar ... Cm {{ Ic end Cm }}
102 Looping construct similar to the C for loop.
103 .It Cm {{ Ic tailq-foreach Ar var head fieldname Cm }} Ar .. Cm {{ Ic end Cm }}
104 Looping construct similar to the queue.h macro TAILQ_FOREACH.
105 .It Cm {{ Ic while Ar ... Cm }} Ar ... Cm {{ Ic end Cm }}
106 Looping construct similar to the C while loop.
107 .It Cm {{ Ar expression Cm \&| Ic unsafe Cm }}
111 .It Cm {{ Ar expression Cm \&| Ic urlescape Cm }}
114 escaped in a way that can be made part of an URL.
115 .It Cm {{ Ar expression Cm }}
118 with the default escaping.
126 reference was written by
127 .An Omar Polo Aq Mt op@openbsd.org .