/usr/share/gtk-doc/html/ctpl/ch01s03.html is in libctpl-doc 0.3.3.dfsg-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Templates syntax</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.75.2">
<link rel="home" href="index.html" title="CTPL Reference Manual">
<link rel="up" href="ch01.html" title="CTPL overview">
<link rel="prev" href="ch01s02.html" title="Working design">
<link rel="next" href="environment-description-syntax.html" title="Environment description syntax">
<meta name="generator" content="GTK-Doc V1.17 (XML mode)">
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2"><tr valign="middle">
<td><a accesskey="p" href="ch01s02.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td>
<td><a accesskey="u" href="ch01.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td>
<td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td>
<th width="100%" align="center">CTPL Reference Manual</th>
<td><a accesskey="n" href="environment-description-syntax.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td>
</tr></table>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="idp53840"></a>Templates syntax</h2></div></div></div>
<p>
CTPL supports 2 kinds of data:
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><span class="term"><a class="link" href="ch01s03.html#raw-data" title="Raw data">Raw data</a></span></p></td>
<td><p>
The actual content of your template, or at least most of it:
unparsed data that will remain (almost) unchanged.
</p></td>
</tr>
<tr>
<td><p><span class="term"><a class="link" href="ch01s03.html#template-blocks" title="Template blocks">Template blocks</a></span></p></td>
<td><p>
The instructions that makes the template engine useful.
</p></td>
</tr>
</tbody>
</table></div>
<p>
</p>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="raw-data"></a>Raw data</h3></div></div></div>
<p>
There is no syntax for the raw data: everything that is not a
template block is raw data. The only exception to this rule is that
the template-blocks-delimiters <code class="code">{</code> and <code class="code">}</code>
must be escaped using a backslash (<code class="code">\</code>), as well as
backslashes themselves. For example, to produce an opening bracket,
you need to write <code class="code">\{</code>, and to produce a backslash you need
to write it twice: <code class="code">\\</code> (the first one escapes the second).
</p>
<div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
<h3 class="title">Note</h3>
<p>
Even if escaping a character that doesn't need to be escaped works
perfectly (thought the escaping backslash doesn't appear), it is
recommended not to do so in order to allow future addition of new
escaping sequences without changes on your template's output.
</p>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="template-blocks"></a>Template blocks</h3></div></div></div>
<p>
Template blocks are delimited with brackets: they are opened with an
unescaped opening bracket (<code class="code">{</code>) and closed with an
unescaped closing bracket (<code class="code">}</code>). All data inside these two
brackets is template instructions.
</p>
<p>
There are 3 instruction types:
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><span class="term">The <code class="code">for</code> loop</span></p></td>
<td>
<p>
The <code class="code">for</code> loop allows to iterate over an expression
that expands to an array, and computes the loop body for each
element in that array.
</p>
<p>
The syntax is the following:
</p>
<div class="informalexample">
<table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td class="listing_lines" align="right"><pre>1</pre></td>
<td class="listing_code"><pre class="programlisting"><span class="gtkdoc opt">{</span><span class="keyword">for</span> <span class="gtkdoc opt"><</span>iterator<span class="gtkdoc opt">></span> in <span class="gtkdoc opt"><</span>expression<span class="gtkdoc opt">>}<</span>loop body<span class="gtkdoc opt">>{</span>end<span class="gtkdoc opt">}</span></pre></td>
</tr>
</tbody>
</table>
</div>
<p>
<code class="code">iterator</code> is the variable name referring to
the current array's element;
<code class="code">expression</code> is an expression (see below) that expands
to the array over which iterate;
<code class="code">loop body</code> is the data that will be evaluated on
each iteration of the loop, and may contain any elements
(raw data or instructions).
</p>
</td>
</tr>
<tr>
<td><p><span class="term">The <code class="code">if</code> switch</span></p></td>
<td>
<p>
The <code class="code">if</code> block is a conditional branching.
</p>
<p>
The syntax is the following:
</p>
<div class="informalexample">
<table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td class="listing_lines" align="right"><pre>1</pre></td>
<td class="listing_code"><pre class="programlisting"><span class="gtkdoc opt">{</span><span class="keyword">if</span> <span class="gtkdoc opt"><</span>expression<span class="gtkdoc opt">>}<</span><span class="keyword">if</span> body<span class="gtkdoc opt">>[{</span><span class="keyword">else</span><span class="gtkdoc opt">}<</span><span class="keyword">else</span> body<span class="gtkdoc opt">>]{</span>end<span class="gtkdoc opt">}</span></pre></td>
</tr>
</tbody>
</table>
</div>
<p>
<code class="code">expression</code> is an expression (see below) that will
be evaluated to a boolean value,
<code class="code">TRUE</code> or <code class="code">FALSE</code>.
</p>
<p>
If the <code class="code">expression</code> evaluates to <code class="code">TRUE</code>,
the <code class="code">if body</code> will be parsed.
If the <code class="code">expression</code> evaluates to <code class="code">FALSE</code>,
the <code class="code">else body</code> will be parsed if any, or nothing
will be done if the <code class="code">else</code> is missing.
</p>
</td>
</tr>
<tr>
<td><p><span class="term">An expression</span></p></td>
<td>
<p>
An expression that will be replaced by its computation result.
</p>
<p>
See <a class="link" href="ctpl-CtplLexerExpr.html" title="CtplLexerExpr">CtplLexerExpr</a>
for details on the syntax of expressions. Basically, it may be
any mathematical-like expression that may include reference(s)
to variable(s). Variable can also be indexed with a C-like
syntax if they expand to an indexable type (basically, an
array). The index expression must expand to an integer or
compatible.
</p>
</td>
</tr>
</tbody>
</table></div>
<p>
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="idp5473824"></a>Examples</h3></div></div></div>
<div class="example">
<a name="idp5474464"></a><p class="title"><b>Example 2. Short template</b></p>
<div class="example-contents">
<p>
</p>
<div class="informalexample">
<table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td class="listing_lines" align="right"><pre>1
2
3</pre></td>
<td class="listing_code"><pre class="programlisting"><span class="gtkdoc opt">{</span><span class="keyword">for</span> i in array<span class="gtkdoc opt">}</span>
<span class="gtkdoc opt">{</span>i<span class="gtkdoc opt">}</span>
<span class="gtkdoc opt">{</span>end<span class="gtkdoc opt">}</span></pre></td>
</tr>
</tbody>
</table>
</div>
<p>
This example will output each item of <code class="code">array</code> on a
newline. Supposing the array <code class="code">[1, 2, 3]</code>, the output will
be:
</p>
<div class="informalexample">
<table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td class="listing_lines" align="right"><pre>1
2
3
4
5</pre></td>
<td class="listing_code"><pre class="programlisting"> <span class="number">1</span>
<span class="number">2</span>
<span class="number">3</span></pre></td>
</tr>
</tbody>
</table>
</div>
<p>
</p>
</div>
</div>
<br class="example-break"><div class="example">
<a name="idp5478272"></a><p class="title"><b>Example 3. Longer template</b></p>
<div class="example-contents">
<p>
Here what may be a template for a member list HTML page:
</p>
<div class="informalexample">
<table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td class="listing_lines" align="right"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13</pre></td>
<td class="listing_code"><pre class="programlisting"><span class="gtkdoc opt"><</span>html<span class="gtkdoc opt">></span>
<span class="gtkdoc opt"><</span>head<span class="gtkdoc opt">></span>
<span class="gtkdoc opt"><</span>title<span class="gtkdoc opt">></span>Member list<span class="gtkdoc opt"></</span>title<span class="gtkdoc opt">></span>
<span class="gtkdoc opt"></</span>head<span class="gtkdoc opt">></span>
<span class="gtkdoc opt"><</span>body<span class="gtkdoc opt">></span>
<span class="gtkdoc opt"><</span>h1<span class="gtkdoc opt">></span>List of our members<span class="gtkdoc opt"><</span>h1<span class="gtkdoc opt">></span>
<span class="gtkdoc opt"><</span>ul <span class="gtkdoc kwc">class</span><span class="gtkdoc opt">=</span><span class="string">"memberlist"</span><span class="gtkdoc opt">></span>
<span class="gtkdoc opt">{</span><span class="keyword">for</span> member in members<span class="gtkdoc opt">}</span>
<span class="gtkdoc opt"><</span>li<span class="gtkdoc opt">>{</span>member<span class="gtkdoc opt">}</</span>li<span class="gtkdoc opt">></span>
<span class="gtkdoc opt">{</span>end<span class="gtkdoc opt">}</span>
<span class="gtkdoc opt"></</span>ul<span class="gtkdoc opt">></span>
<span class="gtkdoc opt"></</span>body<span class="gtkdoc opt">></span>
<span class="gtkdoc opt"></</span>html<span class="gtkdoc opt">></span></pre></td>
</tr>
</tbody>
</table>
</div>
<p>
</p>
</div>
</div>
<br class="example-break"><div class="example">
<a name="idp5481104"></a><p class="title"><b>Example 4. Array indexation</b></p>
<div class="example-contents">
<p>
</p>
<div class="informalexample">
<table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td class="listing_lines" align="right"><pre>1</pre></td>
<td class="listing_code"><pre class="programlisting"><span class="gtkdoc opt">{</span>array<span class="gtkdoc opt">[</span><span class="number">2</span><span class="gtkdoc opt">]}</span></pre></td>
</tr>
</tbody>
</table>
</div>
<p>
This example will output the 3rd element (array indexes starts at
zero) of the array named <code class="code">array</code>.
</p>
</div>
</div>
<br class="example-break">
</div>
</div>
<div class="footer">
<hr>
Generated by GTK-Doc V1.17</div>
</body>
</html>
|