| 1 |
lars |
1 |
<com:TContent ID="body" >
|
|
|
2 |
<h1 id="1601">Templates: Part II</h1>
|
|
|
3 |
|
|
|
4 |
<a name="dct"></a>
|
|
|
5 |
<h2 id="1602">Dynamic Content Tags</h2>
|
|
|
6 |
<p id="190181" class="block-content">
|
|
|
7 |
Dynamic content tags are introduced as shortcuts to some commonly used <a href="?page=Configurations.Templates1#ct">component tags</a>. These tags are mainly used to render contents resulted from evaluating some PHP expressions or statements. They include <a href="#et">expression tags</a>, <a href="#st">statement tags</a>, <a href="#dt">databind tags</a>, <a href="#pt">parameter tags</a>, <a href="#at">asset tags</a> and <a href="#lot">localization tags</a>.
|
|
|
8 |
</p>
|
|
|
9 |
|
|
|
10 |
<a name="et"></a>
|
|
|
11 |
<h3 id="1603">Expression Tags</h3>
|
|
|
12 |
<p id="190182" class="block-content">
|
|
|
13 |
An expression tag represents a PHP expression that is evaluated when the template control is in <tt>PreRender</tt> stage. The expression evaluation result is inserted at the place where the tag resides in the template. The context (namely <tt>$this</tt>) of the expression is the control owning the template.
|
|
|
14 |
</p>
|
|
|
15 |
<p id="190183" class="block-content">
|
|
|
16 |
The format of an expression tag is as follows,
|
|
|
17 |
</p>
|
|
|
18 |
<com:TTextHighlighter Language="prado" CssClass="source block-content" id="code_190079">
|
|
|
19 |
<%= PhpExpression %>
|
|
|
20 |
</com:TTextHighlighter>
|
|
|
21 |
<p id="190184" class="block-content">
|
|
|
22 |
For example, the following expression tag will display the current page title at the place,
|
|
|
23 |
</p>
|
|
|
24 |
<com:TTextHighlighter Language="prado" CssClass="source block-content" id="code_190080">
|
|
|
25 |
<%= $this->Title %>
|
|
|
26 |
</com:TTextHighlighter>
|
|
|
27 |
|
|
|
28 |
<a name="st"></a>
|
|
|
29 |
<h3 id="1604">Statement Tags</h3>
|
|
|
30 |
<p id="190185" class="block-content">
|
|
|
31 |
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 <tt>echo</tt> or <tt>print</tt> in PHP) are displayed at the place where the statement tag resides in the template. The context (namely <tt>$this</tt>) of the statements is the control owning the template. The format of statement tags is as follows,
|
|
|
32 |
</p>
|
|
|
33 |
<com:TTextHighlighter Language="prado" CssClass="source block-content" id="code_190081">
|
|
|
34 |
<%%
|
|
|
35 |
PHP Statements
|
|
|
36 |
%>
|
|
|
37 |
</com:TTextHighlighter>
|
|
|
38 |
<p id="190186" class="block-content">
|
|
|
39 |
The following example displays the current time in Dutch at the place,
|
|
|
40 |
</p>
|
|
|
41 |
<com:TTextHighlighter Language="prado" CssClass="source block-content" id="code_190082">
|
|
|
42 |
<%%
|
|
|
43 |
setlocale(LC_ALL, 'nl_NL');
|
|
|
44 |
echo strftime("%A %e %B %Y",time());
|
|
|
45 |
%>
|
|
|
46 |
</com:TTextHighlighter>
|
|
|
47 |
|
|
|
48 |
<a name="dt"></a>
|
|
|
49 |
<h3 id="1605">Databind Tags</h3>
|
|
|
50 |
<p id="190187" class="block-content">
|
|
|
51 |
Databind tags are similar to expression tags, except that the expressions are evaluated only when a <tt>dataBind()</tt> call is invoked on the controls representing the databind tags. The context (namely <tt>$this</tt>) of a databind expression is the control owning the template. The format of databind tags is as follows,
|
|
|
52 |
</p>
|
|
|
53 |
<com:TTextHighlighter Language="prado" CssClass="source block-content" id="code_190083">
|
|
|
54 |
<%# PhpExpression %>
|
|
|
55 |
</com:TTextHighlighter>
|
|
|
56 |
|
|
|
57 |
<a name="pt"></a>
|
|
|
58 |
<h3 id="1606">Parameter Tags</h3>
|
|
|
59 |
<p id="190188" class="block-content">
|
|
|
60 |
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,
|
|
|
61 |
</p>
|
|
|
62 |
<com:TTextHighlighter Language="prado" CssClass="source block-content" id="code_190084">
|
|
|
63 |
<%$ ParameterName %>
|
|
|
64 |
</com:TTextHighlighter>
|
|
|
65 |
<p id="190189" class="block-content">
|
|
|
66 |
Note, application parameters are usually defined in application configurations or page directory configurations. The parameters are evaluated when the template is instantiated.
|
|
|
67 |
</p>
|
|
|
68 |
|
|
|
69 |
<a name="at"></a>
|
|
|
70 |
<h3 id="1607">Asset Tags</h3>
|
|
|
71 |
<p id="190190" class="block-content">
|
|
|
72 |
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.
|
|
|
73 |
</p>
|
|
|
74 |
<p id="190191" class="block-content">
|
|
|
75 |
The format of asset tags is as follows,
|
|
|
76 |
</p>
|
|
|
77 |
<com:TTextHighlighter Language="prado" CssClass="source block-content" id="code_190085">
|
|
|
78 |
<%~ LocalFileName %>
|
|
|
79 |
</com:TTextHighlighter>
|
|
|
80 |
<p id="190192" class="block-content">
|
|
|
81 |
where <tt>LocalFileName</tt> 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.
|
|
|
82 |
</p>
|
|
|
83 |
<p id="190193" class="block-content">
|
|
|
84 |
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.
|
|
|
85 |
</p>
|
|
|
86 |
|
|
|
87 |
<a name="lot"></a>
|
|
|
88 |
<h3 id="1608">Localization Tags</h3>
|
|
|
89 |
<p id="190194" class="block-content">
|
|
|
90 |
Localization tags represent localized texts. They are in the following format,
|
|
|
91 |
</p>
|
|
|
92 |
<com:TTextHighlighter Language="prado" CssClass="source block-content" id="code_190086">
|
|
|
93 |
<%[string]%>
|
|
|
94 |
</com:TTextHighlighter>
|
|
|
95 |
<p id="190195" class="block-content">
|
|
|
96 |
where <tt>string</tt> will be translated to different languages according to the end-user's language preference. Localization tags are in fact shortcuts to the function call <tt>Prado::localize(string)</tt>.
|
|
|
97 |
</p>
|
|
|
98 |
|
|
|
99 |
|
|
|
100 |
<a name="ut"></a>
|
|
|
101 |
<h3 id="1609">URL Tags</h3>
|
|
|
102 |
<p id="190195" class="block-content">
|
|
|
103 |
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:
|
|
|
104 |
</p>
|
|
|
105 |
<com:TTextHighlighter Language="prado" CssClass="source block-content" id="code_190087">
|
|
|
106 |
<%/ image.jpg %>
|
|
|
107 |
</com:TTextHighlighter>
|
|
|
108 |
</p>
|
|
|
109 |
<p id="190196" class="block-content">
|
|
|
110 |
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.
|
|
|
111 |
</p>
|
|
|
112 |
|
|
|
113 |
<div class="last-modified">$Id: Templates2.page 2568 2008-11-13 11:27:44Z carlgmathisen $</div></com:TContent>
|