eXtension Templates for PHP (XTP for short)

Builtin controls

You don't need to specify anything in template prologue to be able to use built-in controls. These are always available with prefix "php".

RepeaterX

RepeaterX control is available to make it easier for you to create repeating blocks of HTML (in order to avoid using loops). RepeaterX itself can contain up to five inner template blocks:

RepeaterX also defines few properties for your use:

To better illustrate RepeaterX's operation lets consider few simple examples given with their outputs

<php:RepeaterX DataSource='${array("One", "Two", "Three", "Four")}'>
    <HeaderTemplate>
        <table>
    </HeaderTemplate>
    <ItemTemplate>
        <tr>
            <td>#${$this->Index}</td>
            <td>${$this->Item}</td>
        </tr>
    </ItemTemplate>
    <FooterTemplate>
        </table>
    </FooterTemplate>
</php:RepeaterX>

Outputs

<table>
<tr>
    <td>#0</td>
    <td>One</td>
</tr>
<tr>
    <td>#1</td>
    <td>Two</td>
</tr>
<tr>
    <td>#2</td>
    <td>Three</td>
</tr>
<tr>
    <td>#3</td>
    <td>Four</td>
</tr>
</table>

We can see that RepeaterX iterated over DataSource we supplied, applying ItemTemplate template to every value inside.

Within any of RepeaterX's templates can be nested other controls (and vice-versa, RepeaterX can be put inside any other control). Example to illustrate this (using greeting.phpx from one of previous examples like "x:hello"):

<php:RepeaterX DataSource='${array("John", "Thomas", "Marry", "Ivan")}'>
    <HeaderTemplate>
        <table>
    </HeaderTemplate>
    <ItemTemplate>
        <tr>
            <td>#${$this->Index}</td>
            <td><x:hello Name="${$this->Item}"/></td>
        </tr>
    </ItemTemplate>
    <FooterTemplate>
        </table>
    </FooterTemplate>
</php:RepeaterX>

Will output

<table>
<tr>
    <td>#0</td>
    <td>Hello <strong>John!</strong></td>
</tr>
<tr>
    <td>#1</td>
    <td>Hello <strong>Thomas!</strong></td>
</tr>
<tr>
    <td>#2</td>
    <td>Hello <strong>Marry!</strong></td>
</tr>
<tr>
    <td>#3</td>
    <td>Hello <strong>Ivan!</strong></td>
</tr>
</table>

Final example would be to generate simple comma-separated list of names with last name separated with "and", all using Repater. This can be easily achieved using SeparatorTemplate template:

<php:RepeaterX DataSource='${array("John", "Thomas", "Marry", "Ivan")}'>
    <HeaderTemplate>
        Hello <span>
    </HeaderTemplate>
    <ItemTemplate>${$this->Item}</ItemTemplate>
    <SeparatorTemplate>${$this->Index != 3 ? ', ' : ' and '}</SeparatorTemplate>
    <FooterTemplate>
        </span>
    </FooterTemplate>
</php:RepeaterX>

Will output

Hello <span>John, Thomas, Marry and Ivan</span>

« Previous
Reading forms, redirecting user
Next »
Revision history