Skip to content

HTML template files

Peter Corke edited this page Sep 19, 2018 · 4 revisions

The templating is achieved using C Template Library 1.0, by Stephen C. Losen, University of Virginia.

Full documentation is here but only a subset of capability is supported by STL as detailed below. In particular, loops are not supported.

Value substitution

<p>a = <TMPL_VAR name="a"></p>
<p>b = <TMPL_VAR name="b"></p>

Values are strings. The webserver.template() function converts numeric values to strings automatically and with a default format. A row vector will be converted to a comma separated list.

If-else

<TMPL_IF name="a">
    <p>a is exists in the structure.</p>
</TMPL_IF>

displays the program if the variable a in the structure passed to webserver.template(), exists and has a non-null value.

<TMPL_IF name="a" value="2">
    <p>a exists in the structure and is equal to 2.</p>
</TMPL_IF>

displays the program if the variable a in the structure passed to webserver.template(), exists and is equal to 2.

An else-if and else clause is also supported

<TMPL_IF name="a">
    <p>a exists in the structure.</p>
<TMPL_ELSE>
    <p>a does not exist in the structure.</p>
</TMPL_IF>
<TMPL_IF name="a">
    <p>a exists in the structure</p>
<TMPL_ELSEIF name="b"">
    <p>a does not exist in the structure but b does.</p>
</TMPL_IF>

There is no limit on the number of TMPL_ELSEIF statements. The HTML blocks can contain any combinations of HTML and Template tags, ie. you can have substitutions or if-statements.

Include

<TMPL_INCLUDE name="filename">

The tag is replaced with the contents of template file filename and the result is expanded.

Clone this wiki locally