eXtension Templates for PHP (XTP for short)
Connecting things together - X prologue
In order to connect HTML template (.phpx) with appropriate code every template file needs to have prologue where it is specified what class is responsible for handling template, as well as path to the source file where class can be found. In addition, if component is using other components you need to specify them here too. If template is very simple it may not need external class to handle it, and then you can leave prologue out. Here is one example of page prologue:
<@
<option name="class" value="Navigation"/>
<option name="source" value="navigation.php"/>
<control tag="links" prefix="y" path="links.phpx"/>
@>
As you can see from example above template prologue starts with <@ and ends with @>. Between those two tags are normal xml tags with the following meaning:
- option tag is used to specify values
for various options; following options are available:
- class -- specifies class responsible for handling template;
- source -- specifies relative path (from template) to the source file containing class. Please note that both class and source file need to be specified making it possible to keep multiple components' classes in the same source file (this will probably make your project less readable but you can do that).
- control tag is used to specify usage
of other components. It has following attributes:
- tag -- specifies tag used later in html to refer to imported control;
- prefix -- specifies prefix of tag;
- path -- specifies relative path to the imported control template file (.phpx).
Now we can see that previous example means:
- class responsible for controlling component is Navigation
- class Navigation can be found in file navigation.php
- if tag <y:links> is encountered in implementation part of component it would refer to component whose implementation can be found in links.phpx
| « Previous XTP basic organization | Next » Sample component - HTML |
