You are here: WikiStart/Docs/Advanced/External


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.

Including standard HTML

Including with relative paths

Changing the source at runtime