1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
<span metal:use-macro="${id}">
TRUT
</span>
<section data-id="intro" metal:define-macro="intro">
<h1>Introduction</h1>
<h2>Initializing a template</h2>
<strong>Before:</strong>
<pre>$output = new OCP\Template('app', 'template', 'user');</pre>
<strong>After:</strong>
<pre>$tmpl = new OC_TALTemplate('app', 'template', 'user');</pre>
<h2>Assigning a variable</h2>
<strong>Before:</strong>
<pre>$tmpl->assign('myvar', $myvar);</pre>
<strong>After:</strong>
<pre>$tmpl->assign('myvar', $myvar);</pre>
The sharp minds may have noticed that there is no difference ;-)
<h2>Linking to an image</h2>
<strong>Before:</strong>
<pre>
<img class="svg" src="<?php echo image_path('', 'logo-wide.svg'); ?>" alt="ownCloud" />
<img class="svg" src="<?php echo image_path('app', 'someimage.png'); ?>" alt="ownCloud" /></pre>
<strong>After:</strong>
<pre>
<img class="svg" tal:attributes="src image:string:logo-wide.svg" alt="ownCloud" />
<img class="svg" tal:attributes="src image:string:app/someimage.png" alt="ownCloud" /></pre>
<h2>Constructing a link</h2>
<strong>Before:</strong>
<pre>
<a href="<?php echo link_to('', 'index.php'); ?>">Home</a>
<a href="<?php echo link_to('app', 'index.php'); ?>">Some app</a></pre>
<strong>After:</strong>
<pre>
<a tal:attributes="href linkto:string:index.php">Home</a>
<a tal:attributes="href linkto:string:app/index.php">Some app</a></pre>
<h2>Link to remote service</h2>
<strong>Before:</strong>
<pre>
<link rel="stylesheet" href="<?php echo OC_Helper::linkToRemote('core.css') ?>" type="text/css" media="screen" />
<a href="<?php echo OC_Helper::linkToRemote('webdav') ?>">WebDAV</a></pre>
<strong>After:</strong>
<pre>
<link rel="stylesheet" type="text/css" media="screen" tal:attributes="href remote:string:core.css" />
<a tal:attributes="href remote:string:webdav">WebDAV</a></pre>
<p>The latter produces a link to the WebDAV service on the current instance:
<a tal:attributes="href remote:string:webdav">WebDAV</a></p>
<h2>Accessing configuration</h2>
<strong>Before:</strong>
<pre>
ownCloud version: <?php echo OCP\Config::getSystemValue('version'); ?>
Default quota: <?php echo OCP\Config::getAppValue('files', 'default_quota'); ?>
Calendar time zone: <?php echo OCP\Config::getUserValue(OCP\User::getUser(), 'calendar', 'timezone'); ?></pre>
<strong>After:</strong>
<pre>
ownCloud version: $${config:string:sys/version}
Default quota: $${config:string:app/files/default_quota}
Calendar time zone: $${config:string:user/calendar/timezone}</pre>
ownCloud version: ${config:string:sys/version}<br />
Default quota: ${config:string:app/files/default_quota}<br />
Calendar time zone: ${config:string:user/calendar/timezone}<br />
<h2>Translating content</h2>
<strong>Before:</strong>
<pre><p><?php echo $l->t('This will be translated.'); ?><p></pre>
<strong>After:</strong>
<pre><p i18n:translate="">This will be translated.<p></pre>
<a class="readmore" href="http://phptal.org/manual/en/split/i18n-content.html" target="_blank">Read more...</a>
<h2>Translating content with variables</h2>
<strong>Before:</strong>
<p>There is no standardized way to do this currently. I have seen both translation keys using printf formatting
and custom interpolation using e.g. curly brackets.</p>
<strong>After:</strong>
<pre>
<tal:block i18n:name="username" tal:content="user" />
<p i18n:translate="">Your user name is ${username}.</p></pre>
<tal:block i18n:name="username" tal:content="user" />
<p i18n:translate="">Your user name is ${username}.</p>
<p>Or you can wrap it in some markup:</p>
<pre>
<p i18n:translate="">
Welcome back <span i18n:name="username" tal:replace="user"/>.
</p></pre>
<p i18n:translate="">
Welcome back <span i18n:name="username" tal:replace="user"/>.
</p>
<a class="readmore" href="http://phptal.org/manual/en/split/i18n-name.html" target="_blank">Read more...</a>
<h2>Translating attributes.</h2>
<strong>Before:</strong>
<pre><img alt="<?php echo $l->t('Log out');?>" title="<?php echo $l->t('Log out');?>" src="<?php echo image_path('', 'actions/logout.svg'); ?>" /></pre>
<strong>After:</strong>
<pre><img tal:attributes="src image:string:/actions/logout.svg" i18n:attributes="alt;title" alt="Log out" title="Log out" /></pre>
<a href="http://phptal.org/manual/en/split/i18n-attributes.html" target="_blank">See more...</a>
<h2>Iterating</h2>
<pre>
$$arr = array('color' => 'red',
'taste' => 'sweet',
'shape' => 'round',
'name' => 'apple');
</pre>
<strong>Before:</strong>
<pre>
<select size="4">
<?php foreach($$arr as $key=>$value) { ?>
<option value="<php echo $key; >" ><php echo $value; ></option>
</select>
<?php } ?></pre>
<strong>After:</strong>
<pre>
<select size="4">
<option tal:repeat="item arr" tal:attributes="value repeat/item/key" tal:content="item"></option>
</select></pre>
<form>
<select size="4" tal:define="arr php:array('color' => 'red', 'taste' => 'sweet', 'shape' => 'round', 'name' => 'apple')">
<option tal:repeat="item arr" tal:attributes="value repeat/item/key" tal:content="item"></option>
</select>
</form>
<a class="readmore" href="http://phptal.org/manual/en/split/tal-repeat.html" target="_blank">Read more...</a>
<h2>Initializing a template</h2>
<strong>Before:</strong>
<pre></pre>
<strong>After:</strong>
<pre></pre>
</section>
<section data-id="example-1" metal:define-macro="example-1">
<h1>A simple example</h1>
This is actually the main template for this manual.
<pre tal:define="dut php:file_get_contents(apptemplatepath . '/manual.pt')" tal:content="dut">
</pre>
</section>
<section data-id="gotchas" metal:define-macro="gotchas">
<h1>Caveats & Gotchas</h1>
I know
</section>
<section data-id="ref" metal:define-macro="ref">
<h1>References</h1>
<dl>
<dt><a href="http://phptal.org/" target="_blank">PHPTAL</a></dt><dd>The PHP TAL implementation</dd>
<dt><a href="http://phptal.org/manual/en/split/tal-namespace.html" target="_blank">TAL</a></dt><dd>Template Attribute Language</dd>
<dt><a href="http://phptal.org/manual/en/split/phptales.html" target="_blank">TALES</a></dt><dd>TAL Expression Syntax</dd>
<dt><a href="http://phptal.org/manual/en/split/metal.html" target="_blank">METAL</a></dt><dd>Macro Expansion Template Attribute Language</dd>
<dt><a href="http://phptal.org/manual/en/split/i18n.html" target="_blank">i18n namespace</a></dt><dd>Internationalization in TAL</dd>
<dt><a href="http://phptal.org/wiki/doku.php/zopepagetemplates" target="_blank">Zope Page Templates</a></dt><dd>Links and specifications from the original TAL implementation</dd>
</dl>
</section>
|