Templates: Part II

Dynamic Content Tags

Dynamic content tags are introduced as shortcuts to some commonly used component tags. These tags are mainly used to render contents resulted from evaluating some PHP expressions or statements. They include expression tags, statement tags, databind tags, parameter tags, asset tags and localization tags.

Expression Tags

An expression tag represents a PHP expression that is evaluated when the template control is in PreRender stage. The expression evaluation result is inserted at the place where the tag resides in the template. The context (namely $this) of the expression is the control owning the template.

The format of an expression tag is as follows,

<%= PhpExpression %>

For example, the following expression tag will display the current page title at the place,

<%= $this->Title %>

Statement Tags

Statement tags are similar to expression tags, except that statement tags contain PHP statements rather than expressions. The output of the PHP statements (using for example echo or print in PHP) are displayed at the place where the statement tag resides in the template. The context (namely $this) of the statements is the control owning the template. The format of statement tags is as follows,

PHP Statements

The following example displays the current time in Dutch at the place,

setlocale(LC_ALL, 'nl_NL');
echo strftime("%A %e %B %Y",time());

Databind Tags

Databind tags are similar to expression tags, except that the expressions are evaluated only when a dataBind() call is invoked on the controls representing the databind tags. The context (namely $this) of a databind expression is the control owning the template. The format of databind tags is as follows,

<%# PhpExpression %>

Parameter Tags

Parameter tags are used to insert application parameters at the place where they appear in the template. The format of parameter tags is as follows,

<%$ ParameterName %>

Note, application parameters are usually defined in application configurations or page directory configurations. The parameters are evaluated when the template is instantiated.

Asset Tags

Asset tags are used to publish private files and display the corresponding the URLs. For example, if you have an image file that is not Web-accessible and you want to make it visible to end-users, you can use asset tags to publish this file and show the URL to end-users so that they can fetch the published image.

The format of asset tags is as follows,

<%~ LocalFileName %>

where LocalFileName refers to a file path that is relative to the directory containing the current template file. The file path can be a single file or a directory. If the latter, the content in the whole directory will be made accessible by end-users.

BE VERY CAUTIOUS when you are using asset tags as it may expose to end-users files that you probably do not want them to see.

Localization Tags

Localization tags represent localized texts. They are in the following format,


where string will be translated to different languages according to the end-user's language preference. Localization tags are in fact shortcuts to the function call Prado::localize(string).

URL Tags

URL tags are used to insert the relative web url path to the Prado application in the template. You can use it in the following format:

<%/ image.jpg %>

If your Prado application is deployed on http://localhost/pradoapp/, the tag above will produce "/pradoapp/image.jpg". This tag will help you to use the correct file path even with UrlFormat set to Path, or if you are using url mappings.