Examples
These examples show how to define custom tags using the tags provided
by the Templates module. The examples both show how
to use custom tags to control layout exactly and how to define custom
tags working just as regular html tags. The last example shows how it
is possible to combine these two techniques.
Simple header tag
This template definition defines a simple header tag, <rh1>.
It uses <gtext> to render a graphic header. The header is
scalable with the scale argument and the default size is
set to 0.5.
{tmplblock tag=rh1 params=scale}
{tmpldefaultparam
param=scale}0.5{/tmpldefaultparam}
{p}{gtext scale=$scale$}$rh1${/gtext}{br}
{/tmplblock}
Controlling layout
This is an example showing how it is possible to control exactly where
the content will be inserted into the template. In this example there
are three custom tags defined <title>, <description>
and <image>. All tags are inserted into the template using
the <tmplinsert> tag. Observe that there is no
<tmplinsertall> or <tmplinsertexcept> tag in the
example. The result of this is that the only content that will be sent
to the web page after the template has been applied are the content
within the three custom tags. The image is inserted using the
<imgs> tag which automatically sets the correct width and
height of the image.
{tmplblock tag=title}
{h1}$title${/h1}
{/tmplblock}
{tmplblock tag=description}
$description$
{/tmplblock}
{tmplblock tag=image singletag params=src}
{imgs src=$image$}
{/tmplblock}
{tmplinsertblock tag=title}
{table}
{tr}
{td valign=top}
{tmplinsertblock tag=image}
{/td}
{td valign=top}
{tmplinsertblock tag=description}
{/td}
{/tr}
{/table}
Automatic index
In this example the technique from the first and the second example
has been combined. The tag in this example is defined and inserted
twice. The first time it is defined as a link to an anchor point. This
first definition is inserted at the place in the template where the
<tmplinsertblock tag=rh1> is found, creating a list of links
to the headers in the html file. After the tags are inserted the tag
is redefined to a graphic header with an anchor point attached to it.
The value of the anchor point is taken from the text in the header (of
course this will not allow for several identical headers in one html
file). The graphic header with its anchor point will be inserted where
it is found in the content file.
{tmplblock tag=rh1}
{a href="#$rh1$"}{b}$rh1${/b}{/a}{br}
{/tmplblock}
{tmplinsertblock tag=rh1}
.
.
.
{tmplblock tag=rh1 params=scale}
{tmpldefaultparam
param=scale}0.5{/tmpldefaultparam}
{p}
{a name="$rh1$"}
{gtext scale=$scale$}$rh1${/gtext}
{/a}{br}
{/tmplblock}
{tmplinsertall}
|