Go to content Go to blog navigation Go to link heaven

Templation

Recent Updates

Recent Articles

Search

RSS feed Atom feed

Automatic Meta Data: Body, Head & Leading_PHP

2005.10.03 14:10

One of the first things you will notice when exploring templates in Templation are the ubiquitous <%%body%%>, <%%head%%>, and <%%leading_php%%> tags. These are just standard meta data tags, but they are slightly magical because you don't specify them in an html meta tag. Rather they are pulled from your source page by default.

Body

First the body is found via regular expression. Anything between the first set of body tags in the page will be used (note that attributes will not be saved, although they are harmless). The simple regular expression parsing does not allow for nested body tags, but there should only be one body element in an HTML document anyway. If, however, you do not include a body tag, then the entire contents of the page are considered the body (minus leading_php described below).

Head

The head is found using the exact same regular expression match, but it will be empty if you don't have a head element. No suprises there.

Leading PHP

Finally, the most interesting is the leading_php data which is actually found by matching the contents of the first PHP block which must start at the very beginning of the document. This is important, because this is the block where headers may be sent (before output is started). Furthermore, this block should always exist because you need to run the Templation driver script at the top of each page. You must use the full PHP syntax (as opposed to shorthand tags):


<?php ... ?>

It's also important to realize that leading_php will choke if there is a substring ?> within the first PHP block because it will consider that the end of the block. Also, it's sometimes useful to have some PHP not included in the final output (function and class definitions come to mind, more on this in a future post), which can be accomplished simply by closing the first block and immediately opening a new PHP block.

Comments