Much of the power and utility of Cubictemp templates lie in the use of block constructs. A block is exactly what it sounds like - a chunk of text, that may contain newlines, and that is acted on in some way by the template. There are 3 types of block in Cubictemp:
Each of these will be discussed in turn in the following sections.
Cubictemp blocks all have the same basic syntax:
<!--(<block definition>)-->
text
<!--(end)-->
... where <block definition> varies between block types. Blocks can be nested as deeply as you wish, as long as two simple rules are followed:
For instance, this is a well-formed nested block definition:
<!--(<block definition>)-->
<!--(<block definition>)-->
text
<!--(end)-->
text
<!--(end)-->
While this is not:
<!--(<block definition>)-->
<!--(<block definition>)-->
text
<!--(end)-->
text
<!--(end)-->
Readability dictates that the first example is vastly preferable anyway - it just so happens that the internal workings of CubicTemp makes this mandatory.
Before we go on to discuss the use and properties of the different block types, take a moment to look at the block syntax above. Notice that the start and end directives of the block are crafted to look like HTML comments. This means that when you view your unrendered template in a browser, these directives are invisible, but the contents are viewable. This is handy in some circumstances, but it might not always be what we want. In fact, CubicTemp block directives have two different "flavours". The first, in which the directives are comments, but content is visible, you have already met:
<!--(raw)-->
@!bar!@
<!--(end)-->
Sometimes, however, we would prefer to have the entire block appear as a comment. The second block "flavour" allows us to write blocks that are HTML comments in their entirety.
<!--(raw)
@!bar!@
(end)-->
There is no functional difference whatsoever between the two flavours. The two flavours simply allow us to craft templates that can easily be viewed in a web-browser, without being rendered first. We will work through examples of this in the discussion of repeat blocks and named blocks.
<--previous | contents | next--> | (11/16/04) |