Yapter::Templates

Variables and tags are the building blocks that allow you to build pages using the Yapter templating engine.  This information covers the basic elements of a Yapter template.

Templates Explained

Templates consist of standard HTML elements, variables and logical tags.  When the template is parsed by Yapter, variables are replaced with the values you specify and tags are parsed and their specified action occur based on the tags functionality.

Templates Variables

Variables are tokens within a template and/or template BLOCK (explained below) that can be replaced with variable content as required.  Variables in a Yapter template are delcared using this syntax:  {variable}

Templates Tags

These are the template tags, their syntax and an explanation of their usage.  Required elements are displayed in red, while optional elements are displayed in green.  One more important thing, all Yapter template tags MUST be on their own line.  This is because the lines that contain these tags will be removed from the output code during template parsing.

[INCLUDE filename AS name]

The INCLUDE tag allows you to include a template file in another template file.  Optionally you may name it AS a way to internally track this included file under another (often easier) name.  If this parameter is not given, the name of the block will be the filename.  Currently Yapter only supports including fixed content via this tag.  In the future Yapter will provide support for parsing variables and blocks within an included file  Additionally, using a variable for the filename will also be being added.

[BLOCK blockname AS name]

[END blockname]

The BLOCK tag which requires a blockname, allows you to delineate a section within a template that you might want to loop over to create multiple instances of an element within a page. (e.g. A table row.)  Optionally you may name it AS a way to internally track a BLOCK.  Page BLOCKs are also useful in cases where, depending on some variable may require one BLOCK or another.  You can do this by parsing the BLOCK you want and then hiding the other BLOCK using the Yapter::hide() method. Additionally, naming a BLOCK is convenient when you want to REUSE a BLOCK (as explained below).  Alternatively, once you create a BLOCK, you can dynamically clone it within a page using the Yapter::addBlockFromDef() method in your code.

[REUSE blockname AS name ]

The REUSE tag which requires both a blockname and the new name, allows you to clone a BLOCK structure within a page.  You can then populate this new BLOCK with it's own data and handle it separately.

[SET blockname AS name]

[END blockname]

The SET tag is similar to the BLOCK tag, but with one difference, SET-content is never outputted by the Yapter.  SET blocks are used to overwrite content of normal BLOCKs in certain circumstances.  A very useful application for this is error messages.