分类:
2008-06-30 18:48:35
The BLOCK
...END
construct can be used to define
template component blocks which can be processed with the
INCLUDE
, PROCESS
and WRAPPER
directives.
[% BLOCK tabrow %]
[% name %]
[% email %]
[% END %]
A BLOCK
definition can be used before it is defined, as long
as the definition resides in the same file. The block definition itself
does not generate any output.
[% PROCESS tmpblk %]
[% BLOCK tmpblk %] This is OK [% END %]
You can use an anonymous BLOCK
to capture the output of a
template fragment.
[% julius = BLOCK %]
And Caesar's spirit, ranging for revenge,
With Ate by his side come hot from hell,
Shall in these confines with a monarch's voice
Cry 'Havoc', and let slip the dogs of war;
That this foul deed shall smell above the earth
With carrion men, groaning for burial.
[% END %]
Like a named block, it can contain any other template directives which
are processed when the block is defined. The output generated by the
block is then assigned to the variable julius
.
Anonymous BLOCK
s can also be used to define block macros.
The enclosing block is processed each time the macro is called.
[% MACRO locate BLOCK %]
The [% animal %] sat on the [% place %].
[% END %]
[% locate(animal='cat', place='mat') %] # The cat sat on the mat
[% locate(animal='dog', place='log') %] # The dog sat on the log