TracNav menu
- Home
-
Documentation
- Introduction
- Creating templates
-
Adding variables
- Default values
- Accessing variables from other templates
- Using the simpleCondition template
- Creating conditional templates
- Creating alternating rows?
-
Advanced features
- Reading templates from different data sources
- Variable Modifiers
- Improving performance with template caches
- Output Filters
- Input Filters
- Tag Reference
- FAQ
-
Extending patTemplate
- Variable Modifiers
- Template Readers
- Output Filters
- Input Filters
- Custom Tags
- Template Cache
- Template Dumpers
- Download
Including external templates
patTemplate allows you to split your templates in smaller files to re-use templates in several pages. Imagine, you have a template for your page header, which is stored in header.tmpl:
<patTemplate:tmpl name="header"> Here goes the header of your page... </patTemplate:tmpl>
Now, you want to re-use this template inside the template, that displays a page. This can be achieved using the <patTemplate:tmpl/> tag with the src attribute:
<patTemplate:tmpl name="page"> <patTemplate:tmpl name="header_include" src="header.tmpl" parse="on"/> The rest of the page goes here. </patTemplate:tmpl>
Now you can load the page-template as a normal template:
$tmpl = new patTemplate();
$tmpl->readTemplatesFromInput('page.tmpl');
The loaded template structure now is:
+ page
+ header_include
+ header
As you can see, the header template is processed, as if the tag containing this template is nested in the header_include template. This means, that you can also assign variables to the header template, as if it were a normal template contained in page.tmpl.
