One common use for blocks is to declare a named block, and then perform some transformation on it when it is inserted back into the document. One way to do this is to write a transformation function that takes a string and returns a string, and pass it straight in the template namespace for use:
<!--(block codesnippet)-->
for i in range(10):
print i
<!--(end)-->
@!syntaxHighlight(codesnippet)!@
Cubictemp has a special processor syntax to facilitate this use pattern.
<!--(block codesnippet|syntaxHighlight)-->
for i in range(10):
print i
<!--(end)-->
@!codesnippet!@
Using processors is similar to using pipes in Unix shells. Any callable that takes a string and returns a string can be used as a processor. Processors can be chained together:
<!--(block codesnippet|trimWhitespace|syntaxHighlight)-->
for i in range(10):
print i
<!--(end)-->
@!codesnippet!@
In this case, trimWhitespace would be run first, then syntaxHighlight. The processor declarations are just expressions evaluated in the namespace of the block declaration. Processors should be passed in to a template namespace for use.
There is one further refinement to the block syntax. In the examples above, naming the block is redundant - it is created, and then immediately substituted into the template. Anonymous blocks remove this redundancy. An anonymous block is immediately inserted into he template at its place of definition. The following template is equivalent to the last definition above:
<!--(block|trimWhitespace|syntaxHighlight)-->
for i in range(10):
print i
<!--(end)-->
Copyright Nullcube 2008