#block directive allows you to mark a section of your template that
can be selectively reimplemented in a subclass. It is very useful for
changing part of a template without having to copy-paste-and-edit
the entire thing. The output from a template definition that uses blocks will
be identical to the output from the same template with the
#end block tags removed.
(Note: don't be confused by the generic word `block'' in this Guide,
which means a section of code inside any
#TAG ...#end TAG
pair. Thus, an if-block, for-block, def-block, block-block etc. In this
section we are talking only of block-blocks.)
To reimplement the block, use the
#def directive. The magical effect
is that it appears to go back and change the output text at the point the
original block was defined rather than at the location of the
#block testBlock Text in the contents area of the block directive #if $testIt $getFoo() #end if #end block testBlock
You can repeat the block name in the
#end block directive or not, as
#block directives can be nested to any depth.
#block outerBlock Outer block contents #block innerBlock1 inner block1 contents #end block innerBlock1 #block innerBlock2 inner block2 contents #end block innerBlock2 #end block outerBlock
Note that the name of the block is optional for the
#end block tag.
#block directive is equivalent to a
followed immediately by a
#placeholder for the same name. In fact,
that's what Cheetah does. Which means you can use
elsewhere in the template to output the block content again.
There is a one-line
#block syntax analagous to the one-line
The block must not require arguments because the implicit placeholder that's generated will call the block without arguments.