Getting & Installing PHPTemplateLayer

Download the latest version and check that your web server meets the minimum PHP requirements.

Upload the PHPTemplateLayer files to a directory of your choice on your web server, and include the main PHPTemplateLayer class in all of the files in which you want to use it. This can usually be easily achieved by including the class in another include file.


require("classes/class.PHPTemplateLayer.inc.php");

Template Format

You should create your template file in exactly the same manner that you would normally prepare an HTML page, except that it can contain variables and blocks which will be dynamically parsed by your PHP code. Here is a basic exmaple:


<html>
<head>
<title>Example</title>
</head>
<body>
<p>Hello *{firstname}* *{lastname}*</p>
<!-- START BLOCK : CONDITIONALBLOCK -->
<p>Thank you *{firstname}*.Your form has been successfully submitted.</p>
<!-- END BLOCK : CONDITIONALBLOCK -->
</body>
</html>

Variables



*{variablename}*

Insert variables in your HTML template using the asterisk and curly bracket notation where you want them to appear. Asterisks are used in addition to curly brackets so that parts of JavaScript code will automatically not be parsed (otherwise "Ignore" tags would have to be used). Variable names must not contain curly brackets or spaces. Every instance of a variable with the same name inside the same block (or not belonging to a block) will be parsed as the same value. If a variable tag has not been assigned a value, it will be removed from your template during parsing unless you specify 'PARTIAL' parsing during output.

Blocks


<!-- START BLOCK : blockname -->

<!-- END BLOCK : blockname -->

Blocks can be used to conditionally display a block of content or to repeat dynamic content. For example, a confirmation message can be contained inside a block and only shown when certain conditions are met within the PHP code, or a block can be used for each result of a query. Block tags must always exist on a separate line to any other content, and block names must not use curly brackets or spaces. Block names must also be unique - repeated blocks will be removed without being parsed.

Exclude From Parsing


<!-- START NOPARSE -->

<!-- END NOPARSE -->

Any HTML inserted between "No Parse" tags will not be parsed, and any variables or blocks will remain in the HTML without being replaced by their corresponding values. This can be useful, for example, if you want to display examples of unparsed code to website visitors. These tags must always exist on a separate line to any other content.

Exclude From Processing


<!-- START NOPROCESS -->

<!-- END NOPROCESS -->

Any HTML inserted between "No Process" tags will not be processed, meaning that any HTML between these tags will remain unaffected by any post-processing action such as minification. This can be useful, for example, if you want to display examples of non-minified code to website visitors but want to minify the rest of your HTML code. These tags must always exist on a separate line to any other content.

PHPTemplateLayer Object Format

Initiate the PHPTemplateLayer Object and Define a Template

Use the prepare function to define your page's template (View Options).


$PHPTemplateLayer = new PHPTemplateLayer();
$PHPTemplateLayer->prepare("page.htm");

Assign Values To Your Template

Replace the variable tags in your template with the assign or assignGlobal functions.


$PHPTemplateLayer->assign("firstname","Dave");
$PHPTemplateLayer->assignGlobal("firstname","Dave");

Show HTML Blocks

All blocks in your template will remain hidden unless they are created in your PHP code using the block function.


$PHPTemplateLayer->block("CONDITIONALBLOCK");

Display the Parsed Template

Use the display function to display your parsed template (View Options).


$PHPTemplateLayer->display();