mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-05 19:04:27 +02:00
edit examples, make more verbose
This commit is contained in:
@@ -22,7 +22,7 @@
|
|||||||
Template comments are surrounded by asterisks, and that is surrounded
|
Template comments are surrounded by asterisks, and that is surrounded
|
||||||
by the delimiter tags like so: {* this is a comment *}
|
by the delimiter tags like so: {* this is a comment *}
|
||||||
Smarty comments are not displayed in the final output of the template.
|
Smarty comments are not displayed in the final output of the template.
|
||||||
They are used mainly for making the templates more understandable.
|
They are used for making internal notes in the templates.
|
||||||
</para>
|
</para>
|
||||||
<example>
|
<example>
|
||||||
<title>Comments</title>
|
<title>Comments</title>
|
||||||
@@ -116,13 +116,12 @@
|
|||||||
<chapter id="language.variables">
|
<chapter id="language.variables">
|
||||||
<title>Variables</title>
|
<title>Variables</title>
|
||||||
<para>
|
<para>
|
||||||
Smarty has several different types of variables, all of which are
|
Smarty has several different types of variables. The type of the variable
|
||||||
explained in more detail below. The type of the variable depends on what
|
depends on what symbol it is prefixed with (or enclosed within).
|
||||||
symbol it is prefixed with (or enclosed within).
|
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
Variable in Smarty can be either displayed directly or used as arguments
|
Variables in Smarty can be either displayed directly or used as arguments
|
||||||
for function attributes and modifiers, inside conditional expressions,
|
for function attributes and modifiers, inside conditional expressions,
|
||||||
etc. To print a variable, simply enclose it in the delimiters so that it
|
etc. To print a variable, simply enclose it in the delimiters so that it
|
||||||
is the only thing contained between them. Examples:
|
is the only thing contained between them. Examples:
|
||||||
@@ -137,8 +136,10 @@
|
|||||||
<sect1 id="language.assigned.variables">
|
<sect1 id="language.assigned.variables">
|
||||||
<title>Variables assigned from PHP</title>
|
<title>Variables assigned from PHP</title>
|
||||||
<para>
|
<para>
|
||||||
Variables that are assigned from PHP are referenced by preceding
|
Variables that are assigned from PHP are referenced by preceding them with
|
||||||
them with a dollar sign <literal>$</literal>.
|
a dollar sign <literal>$</literal>. Variables assigned from within the
|
||||||
|
template with the <link linkend="language.function.assign">assign</link>
|
||||||
|
function are also displayed this way.
|
||||||
</para>
|
</para>
|
||||||
<example>
|
<example>
|
||||||
|
|
||||||
@@ -165,6 +166,18 @@ Your last login was on January 11th, 2001.</programlisting>
|
|||||||
<example>
|
<example>
|
||||||
<title>accessing associative array variables</title>
|
<title>accessing associative array variables</title>
|
||||||
<programlisting>
|
<programlisting>
|
||||||
|
index.php:
|
||||||
|
|
||||||
|
$smarty = new Smarty;
|
||||||
|
$smarty->assign('Contacts',
|
||||||
|
array('fax' => '555-222-9876',
|
||||||
|
'email' => 'zaphod@slartibartfast.com',
|
||||||
|
'phone' => array('home' => '555-444-3333',
|
||||||
|
'cell' => '555-111-1234')));
|
||||||
|
$smarty->display('index.tpl');
|
||||||
|
|
||||||
|
index.tpl:
|
||||||
|
|
||||||
{$Contacts.fax}<br>
|
{$Contacts.fax}<br>
|
||||||
{$Contacts.email}<br>
|
{$Contacts.email}<br>
|
||||||
{* you can print arrays of arrays as well *}
|
{* you can print arrays of arrays as well *}
|
||||||
@@ -176,8 +189,7 @@ OUTPUT:
|
|||||||
555-222-9876<br>
|
555-222-9876<br>
|
||||||
zaphod@slartibartfast.com<br>
|
zaphod@slartibartfast.com<br>
|
||||||
555-444-3333<br>
|
555-444-3333<br>
|
||||||
555-111-1234<br>
|
555-111-1234<br></programlisting>
|
||||||
</programlisting>
|
|
||||||
</example>
|
</example>
|
||||||
</sect2>
|
</sect2>
|
||||||
<sect2 id="language.variables.array.indexes">
|
<sect2 id="language.variables.array.indexes">
|
||||||
@@ -189,11 +201,30 @@ zaphod@slartibartfast.com<br>
|
|||||||
<example>
|
<example>
|
||||||
<title>accessing arrays by index</title>
|
<title>accessing arrays by index</title>
|
||||||
<programlisting>
|
<programlisting>
|
||||||
|
index.php:
|
||||||
|
|
||||||
|
$smarty = new Smarty;
|
||||||
|
$smarty->assign('Contacts',
|
||||||
|
array('555-222-9876',
|
||||||
|
'zaphod@slartibartfast.com',
|
||||||
|
array('555-444-3333',
|
||||||
|
'555-111-1234')));
|
||||||
|
$smarty->display('index.tpl');
|
||||||
|
|
||||||
|
index.tpl:
|
||||||
|
|
||||||
{$Contacts[0]}<br>
|
{$Contacts[0]}<br>
|
||||||
{$Contacts[1]}<br>
|
{$Contacts[1]}<br>
|
||||||
{* you can print arrays of arrays as well *}
|
{* you can print arrays of arrays as well *}
|
||||||
{$Contacts[0][0]}<br>
|
{$Contacts[2][0]}<br>
|
||||||
{$Contacts[0][1]}<br></programlisting>
|
{$Contacts[2][1]}<br>
|
||||||
|
|
||||||
|
OUTPUT:
|
||||||
|
|
||||||
|
555-222-9876<br>
|
||||||
|
zaphod@slartibartfast.com<br>
|
||||||
|
555-444-3333<br>
|
||||||
|
555-111-1234<br></programlisting>
|
||||||
</example>
|
</example>
|
||||||
</sect2>
|
</sect2>
|
||||||
<sect2 id="language.variables.objects">
|
<sect2 id="language.variables.objects">
|
||||||
@@ -226,6 +257,17 @@ email: zaphod@slartibartfast.com<br></programlisting>
|
|||||||
|
|
||||||
<title>config variables</title>
|
<title>config variables</title>
|
||||||
<programlisting>
|
<programlisting>
|
||||||
|
foo.conf:
|
||||||
|
|
||||||
|
pageTitle = "This is mine"
|
||||||
|
bodyBgColor = "#eeeeee"
|
||||||
|
tableBorderSize = "3"
|
||||||
|
tableBgColor = "#bbbbbb"
|
||||||
|
rowBgColor = "#cccccc"
|
||||||
|
|
||||||
|
index.tpl:
|
||||||
|
|
||||||
|
{config_load file="foo.conf"}
|
||||||
<html>
|
<html>
|
||||||
<title>{#pageTitle#}</title>
|
<title>{#pageTitle#}</title>
|
||||||
<body bgcolor="{#bodyBgColor#}">
|
<body bgcolor="{#bodyBgColor#}">
|
||||||
@@ -237,6 +279,21 @@ email: zaphod@slartibartfast.com<br></programlisting>
|
|||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
</body>
|
</body>
|
||||||
|
</html>
|
||||||
|
|
||||||
|
OUTPUT:
|
||||||
|
|
||||||
|
<html>
|
||||||
|
<title>This is mine</title>
|
||||||
|
<body bgcolor="#eeeeee">
|
||||||
|
<table border="3" bgcolor="#bbbbbb">
|
||||||
|
<tr bgcolor="#cccccc">
|
||||||
|
<td>First</td>
|
||||||
|
<td>Last</td>
|
||||||
|
<td>Address</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</body>
|
||||||
</html></programlisting>
|
</html></programlisting>
|
||||||
</example>
|
</example>
|
||||||
<para>
|
<para>
|
||||||
@@ -265,10 +322,10 @@ email: zaphod@slartibartfast.com<br></programlisting>
|
|||||||
|
|
||||||
<title>displaying request variables</title>
|
<title>displaying request variables</title>
|
||||||
<programlisting>
|
<programlisting>
|
||||||
{* display the variable "page" given in the URL, or from a form using the GET method *}
|
{* display value of page from URL (GET) http://www.domain.com/index.php?page=foo *}
|
||||||
{$smarty.get.page}
|
{$smarty.get.page}
|
||||||
|
|
||||||
{* display the variable "page" from a form using the POST method *}
|
{* display the variable "page" from a form a form (POST) *}
|
||||||
{$smarty.post.page}
|
{$smarty.post.page}
|
||||||
|
|
||||||
{* display the value of the cookie "username" *}
|
{* display the value of the cookie "username" *}
|
||||||
@@ -370,6 +427,14 @@ Topic: {$topic|truncate:40:"..."}</programlisting>
|
|||||||
<example>
|
<example>
|
||||||
<title>capitalize</title>
|
<title>capitalize</title>
|
||||||
<programlisting>
|
<programlisting>
|
||||||
|
index.php:
|
||||||
|
|
||||||
|
$smarty = new Smarty;
|
||||||
|
$smarty->assign('articleTitle', 'Police begin campaign to rundown jaywalkers.');
|
||||||
|
$smarty->display('index.tpl');
|
||||||
|
|
||||||
|
index.tpl:
|
||||||
|
|
||||||
{$articleTitle}
|
{$articleTitle}
|
||||||
{$articleTitle|capitalize}
|
{$articleTitle|capitalize}
|
||||||
|
|
||||||
@@ -387,13 +452,20 @@ Police Begin Campaign To Rundown Jaywalkers.</programlisting>
|
|||||||
<example>
|
<example>
|
||||||
<title>count_characters</title>
|
<title>count_characters</title>
|
||||||
<programlisting>
|
<programlisting>
|
||||||
|
index.php:
|
||||||
|
|
||||||
|
$smarty = new Smarty;
|
||||||
|
$smarty->assign('articleTitle', 'Cold Wave Linked to Temperatures.');
|
||||||
|
$smarty->display('index.tpl');
|
||||||
|
|
||||||
|
index.tpl:
|
||||||
|
|
||||||
{$articleTitle}
|
{$articleTitle}
|
||||||
{$articleTitle|count_characters}
|
{$articleTitle|count_characters}
|
||||||
|
|
||||||
OUTPUT:
|
OUTPUT:
|
||||||
|
|
||||||
Cold Wave Linked to Temperatures
|
Cold Wave Linked to Temperatures.
|
||||||
32</programlisting>
|
32</programlisting>
|
||||||
</example>
|
</example>
|
||||||
</sect1>
|
</sect1>
|
||||||
@@ -405,6 +477,13 @@ Cold Wave Linked to Temperatures
|
|||||||
<example>
|
<example>
|
||||||
<title>count_paragraphs</title>
|
<title>count_paragraphs</title>
|
||||||
<programlisting>
|
<programlisting>
|
||||||
|
index.php:
|
||||||
|
|
||||||
|
$smarty = new Smarty;
|
||||||
|
$smarty->assign('articleTitle', 'War Dims Hope for Peace. Child's Death Ruins Couple's Holiday.');
|
||||||
|
$smarty->display('index.tpl');
|
||||||
|
|
||||||
|
index.tpl:
|
||||||
|
|
||||||
{$articleTitle}
|
{$articleTitle}
|
||||||
{$articleTitle|count_paragraphs}
|
{$articleTitle|count_paragraphs}
|
||||||
@@ -425,6 +504,13 @@ Man is Fatally Slain. Death Causes Loneliness, Feeling of Isolation.
|
|||||||
<example>
|
<example>
|
||||||
<title>count_sentences</title>
|
<title>count_sentences</title>
|
||||||
<programlisting>
|
<programlisting>
|
||||||
|
index.php:
|
||||||
|
|
||||||
|
$smarty = new Smarty;
|
||||||
|
$smarty->assign('articleTitle', 'Two Soviet Ships Collide - One Dies. Enraged Cow Injures Farmer with Axe.');
|
||||||
|
$smarty->display('index.tpl');
|
||||||
|
|
||||||
|
index.tpl:
|
||||||
|
|
||||||
{$articleTitle}
|
{$articleTitle}
|
||||||
{$articleTitle|count_sentences}
|
{$articleTitle|count_sentences}
|
||||||
@@ -443,6 +529,13 @@ Two Soviet Ships Collide - One Dies. Enraged Cow Injures Farmer with Axe.
|
|||||||
<example>
|
<example>
|
||||||
<title>count_words</title>
|
<title>count_words</title>
|
||||||
<programlisting>
|
<programlisting>
|
||||||
|
index.php:
|
||||||
|
|
||||||
|
$smarty = new Smarty;
|
||||||
|
$smarty->assign('articleTitle', 'Dealers Will Hear Car Talk at Noon.');
|
||||||
|
$smarty->display('index.tpl');
|
||||||
|
|
||||||
|
index.tpl:
|
||||||
|
|
||||||
{$articleTitle}
|
{$articleTitle}
|
||||||
{$articleTitle|count_words}
|
{$articleTitle|count_words}
|
||||||
@@ -501,14 +594,29 @@ Dealers Will Hear Car Talk at Noon.
|
|||||||
<example>
|
<example>
|
||||||
<title>date_format</title>
|
<title>date_format</title>
|
||||||
<programlisting>
|
<programlisting>
|
||||||
|
index.php:
|
||||||
|
|
||||||
|
$smarty = new Smarty;
|
||||||
|
$smarty->assign('yesterday', strtotime('-1 day'));
|
||||||
|
$smarty->display('index.tpl');
|
||||||
|
|
||||||
|
index.tpl:
|
||||||
|
|
||||||
|
|
||||||
{$smarty.now|date_format}
|
{$smarty.now|date_format}
|
||||||
{$smarty.now|date_format:"%A, %B %e, %Y"}
|
{$smarty.now|date_format:"%A, %B %e, %Y"}
|
||||||
{$smarty.now|date_format:"%H:%M:%S"}
|
{$smarty.now|date_format:"%H:%M:%S"}
|
||||||
|
{$yesterday|date_format}
|
||||||
|
{$yesterday|date_format:"%A, %B %e, %Y"}
|
||||||
|
{$yesterday|date_format:"%H:%M:%S"}
|
||||||
|
|
||||||
OUTPUT:
|
OUTPUT:
|
||||||
|
|
||||||
Feb 6, 2001
|
Feb 6, 2001
|
||||||
Tuesday, February 6, 2001
|
Tuesday, February 6, 2001
|
||||||
|
14:33:00
|
||||||
|
Feb 5, 2001
|
||||||
|
Monday, February 5, 2001
|
||||||
14:33:00</programlisting>
|
14:33:00</programlisting>
|
||||||
</example>
|
</example>
|
||||||
<example>
|
<example>
|
||||||
@@ -637,11 +745,20 @@ system's manpage for a full list of valid specifiers.</programlisting>
|
|||||||
<example>
|
<example>
|
||||||
<title>default</title>
|
<title>default</title>
|
||||||
<programlisting>
|
<programlisting>
|
||||||
{* this will display "no title" (without the quotes) if $articleTitle is empty *}
|
index.php:
|
||||||
|
|
||||||
|
$smarty = new Smarty;
|
||||||
|
$smarty->assign('articleTitle', 'Dealers Will Hear Car Talk at Noon.');
|
||||||
|
$smarty->display('index.tpl');
|
||||||
|
|
||||||
|
index.tpl:
|
||||||
|
|
||||||
{$articleTitle|default:"no title"}
|
{$articleTitle|default:"no title"}
|
||||||
|
{$myTitle|default:"no title"}
|
||||||
|
|
||||||
OUTPUT:
|
OUTPUT:
|
||||||
|
|
||||||
|
Dealers Will Hear Car Talk at Noon.
|
||||||
no title</programlisting>
|
no title</programlisting>
|
||||||
</example>
|
</example>
|
||||||
</sect1>
|
</sect1>
|
||||||
@@ -688,6 +805,14 @@ no title</programlisting>
|
|||||||
<example>
|
<example>
|
||||||
<title>escape</title>
|
<title>escape</title>
|
||||||
<programlisting>
|
<programlisting>
|
||||||
|
index.php:
|
||||||
|
|
||||||
|
$smarty = new Smarty;
|
||||||
|
$smarty->assign('articleTitle', "'Stiff Opposition Expected to Casketless Funeral Plan'");
|
||||||
|
$smarty->display('index.tpl');
|
||||||
|
|
||||||
|
index.tpl:
|
||||||
|
|
||||||
{$articleTitle}
|
{$articleTitle}
|
||||||
{$articleTitle|escape}
|
{$articleTitle|escape}
|
||||||
{$articleTitle|escape:"html"} {* escapes & " ' < > *}
|
{$articleTitle|escape:"html"} {* escapes & " ' < > *}
|
||||||
@@ -755,6 +880,14 @@ href="mailto:%62%6f%62%40%6d%65%2e%6e%65%74">&#x62;&#x6f;&#x62;&a
|
|||||||
<example>
|
<example>
|
||||||
<title>indent</title>
|
<title>indent</title>
|
||||||
<programlisting>
|
<programlisting>
|
||||||
|
index.php:
|
||||||
|
|
||||||
|
$smarty = new Smarty;
|
||||||
|
$smarty->assign('articleTitle', 'NJ judge to rule on nude beach.');
|
||||||
|
$smarty->display('index.tpl');
|
||||||
|
|
||||||
|
index.tpl:
|
||||||
|
|
||||||
{$articleTitle}
|
{$articleTitle}
|
||||||
|
|
||||||
{$articleTitle|indent}
|
{$articleTitle|indent}
|
||||||
@@ -790,6 +923,14 @@ Statistics show that teen pregnancy drops off significantly after 25.
|
|||||||
<example>
|
<example>
|
||||||
<title>lower</title>
|
<title>lower</title>
|
||||||
<programlisting>
|
<programlisting>
|
||||||
|
index.php:
|
||||||
|
|
||||||
|
$smarty = new Smarty;
|
||||||
|
$smarty->assign('articleTitle', 'Two Convicts Evade Noose, Jury Hung.');
|
||||||
|
$smarty->display('index.tpl');
|
||||||
|
|
||||||
|
index.tpl:
|
||||||
|
|
||||||
{$articleTitle}
|
{$articleTitle}
|
||||||
{$articleTitle|lower}
|
{$articleTitle|lower}
|
||||||
|
|
||||||
@@ -842,6 +983,14 @@ two convicts evade noose, jury hung.</programlisting>
|
|||||||
<example>
|
<example>
|
||||||
<title>regex_replace</title>
|
<title>regex_replace</title>
|
||||||
<programlisting>
|
<programlisting>
|
||||||
|
index.php:
|
||||||
|
|
||||||
|
$smarty = new Smarty;
|
||||||
|
$smarty->assign('articleTitle', "Infertility unlikely to\nbe passed on, experts say.");
|
||||||
|
$smarty->display('index.tpl');
|
||||||
|
|
||||||
|
index.tpl:
|
||||||
|
|
||||||
{* replace each carriage return, tab & new line with a space *}
|
{* replace each carriage return, tab & new line with a space *}
|
||||||
|
|
||||||
{$articleTitle}
|
{$articleTitle}
|
||||||
@@ -850,8 +999,8 @@ two convicts evade noose, jury hung.</programlisting>
|
|||||||
OUTPUT:
|
OUTPUT:
|
||||||
|
|
||||||
Infertility unlikely to
|
Infertility unlikely to
|
||||||
be passed on, experts say
|
be passed on, experts say.
|
||||||
Infertility unlikely to be passed on, experts say</programlisting>
|
Infertility unlikely to be passed on, experts say.</programlisting>
|
||||||
</example>
|
</example>
|
||||||
</sect1>
|
</sect1>
|
||||||
<sect1 id="language.modifier.replace">
|
<sect1 id="language.modifier.replace">
|
||||||
@@ -896,6 +1045,14 @@ Infertility unlikely to be passed on, experts say</programlisting>
|
|||||||
<example>
|
<example>
|
||||||
<title>replace</title>
|
<title>replace</title>
|
||||||
<programlisting>
|
<programlisting>
|
||||||
|
index.php:
|
||||||
|
|
||||||
|
$smarty = new Smarty;
|
||||||
|
$smarty->assign('articleTitle', "Child's Stool Great for Use in Garden.");
|
||||||
|
$smarty->display('index.tpl');
|
||||||
|
|
||||||
|
index.tpl:
|
||||||
|
|
||||||
{$articleTitle}
|
{$articleTitle}
|
||||||
{$articleTitle|replace:"Garden":"Vineyard"}
|
{$articleTitle|replace:"Garden":"Vineyard"}
|
||||||
{$articleTitle|replace:" ":" "}
|
{$articleTitle|replace:" ":" "}
|
||||||
@@ -944,6 +1101,14 @@ Child's Stool Great for Use in Garden.</programlisting>
|
|||||||
<example>
|
<example>
|
||||||
<title>spacify</title>
|
<title>spacify</title>
|
||||||
<programlisting>
|
<programlisting>
|
||||||
|
index.php:
|
||||||
|
|
||||||
|
$smarty = new Smarty;
|
||||||
|
$smarty->assign('articleTitle', 'Something Went Wrong in Jet Crash, Experts Say.');
|
||||||
|
$smarty->display('index.tpl');
|
||||||
|
|
||||||
|
index.tpl:
|
||||||
|
|
||||||
{$articleTitle}
|
{$articleTitle}
|
||||||
{$articleTitle|spacify}
|
{$articleTitle|spacify}
|
||||||
{$articleTitle|spacify:"^^"}
|
{$articleTitle|spacify:"^^"}
|
||||||
@@ -991,6 +1156,14 @@ S^^o^^m^^e^^t^^h^^i^^n^^g^^ ^^W^^e^^n^^t^^ ^^W^^r^^o^^n^^g^^ ^^i^^n^^ ^^J^^e^^t^
|
|||||||
<example>
|
<example>
|
||||||
<title>string_format</title>
|
<title>string_format</title>
|
||||||
<programlisting>
|
<programlisting>
|
||||||
|
index.php:
|
||||||
|
|
||||||
|
$smarty = new Smarty;
|
||||||
|
$smarty->assign('number', 23.5787446);
|
||||||
|
$smarty->display('index.tpl');
|
||||||
|
|
||||||
|
index.tpl:
|
||||||
|
|
||||||
{$number}
|
{$number}
|
||||||
{$number|string_format:"%.2f"}
|
{$number|string_format:"%.2f"}
|
||||||
{$number|string_format:"%d"}
|
{$number|string_format:"%d"}
|
||||||
@@ -1018,6 +1191,14 @@ OUTPUT:
|
|||||||
<example>
|
<example>
|
||||||
<title>strip</title>
|
<title>strip</title>
|
||||||
<programlisting>
|
<programlisting>
|
||||||
|
index.php:
|
||||||
|
|
||||||
|
$smarty = new Smarty;
|
||||||
|
$smarty->assign('articleTitle', "Grandmother of\neight makes\t hole in one.");
|
||||||
|
$smarty->display('index.tpl');
|
||||||
|
|
||||||
|
index.tpl:
|
||||||
|
|
||||||
{$articleTitle}
|
{$articleTitle}
|
||||||
{$articleTitle|strip}
|
{$articleTitle|strip}
|
||||||
{$articleTitle|strip:"&nbsp;"}
|
{$articleTitle|strip:"&nbsp;"}
|
||||||
@@ -1025,9 +1206,9 @@ OUTPUT:
|
|||||||
OUTPUT:
|
OUTPUT:
|
||||||
|
|
||||||
Grandmother of
|
Grandmother of
|
||||||
eight makes hole in one
|
eight makes hole in one.
|
||||||
Grandmother of eight makes hole in one
|
Grandmother of eight makes hole in one.
|
||||||
Grandmother&nbsp;of&nbsp;eight&nbsp;makes&nbsp;hole&nbsp;in&nbsp;one</programlisting>
|
Grandmother&nbsp;of&nbsp;eight&nbsp;makes&nbsp;hole&nbsp;in&nbsp;one.</programlisting>
|
||||||
</example>
|
</example>
|
||||||
</sect1>
|
</sect1>
|
||||||
<sect1 id="language.modifier.strip.tags">
|
<sect1 id="language.modifier.strip.tags">
|
||||||
@@ -1038,6 +1219,14 @@ Grandmother&nbsp;of&nbsp;eight&nbsp;makes&nbsp;hole&nbsp;in&
|
|||||||
<example>
|
<example>
|
||||||
<title>strip_tags</title>
|
<title>strip_tags</title>
|
||||||
<programlisting>
|
<programlisting>
|
||||||
|
index.php:
|
||||||
|
|
||||||
|
$smarty = new Smarty;
|
||||||
|
$smarty->assign('articleTitle', "Blind Woman Gets <font face=\"helvetica\">New Kidney</font> from Dad she Hasn't Seen in <b>years</b>.");
|
||||||
|
$smarty->display('index.tpl');
|
||||||
|
|
||||||
|
index.tpl:
|
||||||
|
|
||||||
{$articleTitle}
|
{$articleTitle}
|
||||||
{$articleTitle|strip_tags}
|
{$articleTitle|strip_tags}
|
||||||
|
|
||||||
@@ -1104,6 +1293,14 @@ Blind Woman Gets New Kidney from Dad she Hasn't Seen in years.</programlisting>
|
|||||||
<example>
|
<example>
|
||||||
<title>truncate</title>
|
<title>truncate</title>
|
||||||
<programlisting>
|
<programlisting>
|
||||||
|
index.php:
|
||||||
|
|
||||||
|
$smarty = new Smarty;
|
||||||
|
$smarty->assign('articleTitle', 'Two Sisters Reunite after Eighteen Years at Checkout Counter.');
|
||||||
|
$smarty->display('index.tpl');
|
||||||
|
|
||||||
|
index.tpl:
|
||||||
|
|
||||||
{$articleTitle}
|
{$articleTitle}
|
||||||
{$articleTitle|truncate}
|
{$articleTitle|truncate}
|
||||||
{$articleTitle|truncate:30}
|
{$articleTitle|truncate:30}
|
||||||
@@ -1131,6 +1328,14 @@ Two Sisters Reunite after E...</programlisting>
|
|||||||
<example>
|
<example>
|
||||||
<title>upper</title>
|
<title>upper</title>
|
||||||
<programlisting>
|
<programlisting>
|
||||||
|
index.php:
|
||||||
|
|
||||||
|
$smarty = new Smarty;
|
||||||
|
$smarty->assign('articleTitle', "If Strike isn't Settled Quickly it may Last a While.");
|
||||||
|
$smarty->display('index.tpl');
|
||||||
|
|
||||||
|
index.tpl:
|
||||||
|
|
||||||
{$articleTitle}
|
{$articleTitle}
|
||||||
{$articleTitle|upper}
|
{$articleTitle|upper}
|
||||||
|
|
||||||
@@ -1196,6 +1401,14 @@ IF STRIKE ISN'T SETTLED QUICKLY IT MAY LAST A WHILE.</programlisting>
|
|||||||
<example>
|
<example>
|
||||||
<title>wordwrap</title>
|
<title>wordwrap</title>
|
||||||
<programlisting>
|
<programlisting>
|
||||||
|
index.php:
|
||||||
|
|
||||||
|
$smarty = new Smarty;
|
||||||
|
$smarty->assign('articleTitle', "Blind woman gets new kidney from dad she hasn't seen in years.");
|
||||||
|
$smarty->display('index.tpl');
|
||||||
|
|
||||||
|
index.tpl:
|
||||||
|
|
||||||
{$articleTitle}
|
{$articleTitle}
|
||||||
|
|
||||||
{$articleTitle|wordwrap:30}
|
{$articleTitle|wordwrap:30}
|
||||||
@@ -1241,6 +1454,14 @@ s.</programlisting>
|
|||||||
<example>
|
<example>
|
||||||
<title>combining modifiers</title>
|
<title>combining modifiers</title>
|
||||||
<programlisting>
|
<programlisting>
|
||||||
|
index.php:
|
||||||
|
|
||||||
|
$smarty = new Smarty;
|
||||||
|
$smarty->assign('articleTitle', 'Smokers are Productive, but Death Cuts Efficiency.');
|
||||||
|
$smarty->display('index.tpl');
|
||||||
|
|
||||||
|
index.tpl:
|
||||||
|
|
||||||
{$articleTitle}
|
{$articleTitle}
|
||||||
{$articleTitle|upper|spacify}
|
{$articleTitle|upper|spacify}
|
||||||
{$articleTitle|lower|spacify|truncate}
|
{$articleTitle|lower|spacify|truncate}
|
||||||
|
@@ -180,22 +180,20 @@ $smarty->autoload_filters = array('pre' => array('trim', 'stamp'),
|
|||||||
<sect1 id="variable.compile.check">
|
<sect1 id="variable.compile.check">
|
||||||
<title>$compile_check</title>
|
<title>$compile_check</title>
|
||||||
<para>
|
<para>
|
||||||
Upon each invocation of the PHP application, Smarty tests to
|
Upon each invocation of the PHP application, Smarty tests to see if the
|
||||||
see if the current template has changed (later time stamp)
|
current template has changed (different time stamp) since the last time
|
||||||
since the last time it was compiled. If it has changed, it
|
it was compiled. If it has changed, it recompiles that template. If the
|
||||||
recompiles that template. As of 1.4.0, if the template has not
|
template has not been compiled, it will compile regardless of this
|
||||||
been compiled, it will compile regardless of this setting. By
|
setting. By default this variable is set to true. Once an application is
|
||||||
default this variable is set to true. Once an application is
|
put into production (templates won't be changing), the compile_check
|
||||||
put into production (templates won't be changing), the
|
step is no longer needed. Be sure to set $compile_check to "false" for
|
||||||
compile_check step is no longer needed. Be sure to set
|
maximal performance. Note that if you change this to "false" and a
|
||||||
$compile_check to "false" to improve performance! Note that if
|
template file is changed, you will *not* see the change since the
|
||||||
you change this to "false" and a template file is changed, you
|
template will not get recompiled. If caching is enabled and
|
||||||
will *not* see the change since the template will not get
|
compile_check is enabled, then the cache files will get regenerated if
|
||||||
recompiled. If caching is enabled and compile_check is enabled,
|
an involved template file or config file was updated. See <link
|
||||||
then the cache files will get regenerated if an involved
|
linkend="variable.force.compile">$force_compile</link> or <link
|
||||||
template file was updated. See <link
|
linkend="api.clear.compiled.tpl">clear_compiled_tpl</link>.
|
||||||
linkend="variable.force.compile">$force_compile</link> or <link
|
|
||||||
linkend="api.clear.compiled.tpl">clear_compiled_tpl</link>.
|
|
||||||
</para>
|
</para>
|
||||||
</sect1>
|
</sect1>
|
||||||
<sect1 id="variable.force.compile">
|
<sect1 id="variable.force.compile">
|
||||||
@@ -302,6 +300,41 @@ $smarty->autoload_filters = array('pre' => array('trim', 'stamp'),
|
|||||||
cached content without <command>insert</command> tags.
|
cached content without <command>insert</command> tags.
|
||||||
</para>
|
</para>
|
||||||
</sect1>
|
</sect1>
|
||||||
|
<sect1 id="variable.config.overwrite">
|
||||||
|
<title>$config_overwrite</title>
|
||||||
|
<para>
|
||||||
|
If set to true, variables read in from config files will overwrite each
|
||||||
|
other. Otherwise, the variables will be pushed onto an array. This is
|
||||||
|
helpful if you want to store arrays of data in config files, just list
|
||||||
|
each element multiple times. true by default.
|
||||||
|
</para>
|
||||||
|
</sect1>
|
||||||
|
<sect1 id="variable.config.booleanize">
|
||||||
|
<title>$config_booleanize</title>
|
||||||
|
<para>
|
||||||
|
If set to true, config file values of on/true/yes and off/false/no get
|
||||||
|
converted to boolean values automatically. This way you can use the
|
||||||
|
values in the template like so: {if #foobar#} ... {/if}. If foobar was
|
||||||
|
on, true or yes, the {if} statement will execute. true by default.
|
||||||
|
</para>
|
||||||
|
</sect1>
|
||||||
|
<sect1 id="variable.config.read.hidden">
|
||||||
|
<title>$config_read_hidden</title>
|
||||||
|
<para>
|
||||||
|
If set to true, hidden sections (section names beginning with a period)
|
||||||
|
in config files can be read from templates. Typically you would leave
|
||||||
|
this false, that way you can store sensitive data in the config files
|
||||||
|
such as database parameters and not worry about the template loading
|
||||||
|
them. false by default.
|
||||||
|
</para>
|
||||||
|
</sect1>
|
||||||
|
<sect1 id="variable.config.fix.newlines">
|
||||||
|
<title>$config_fix_newlines</title>
|
||||||
|
<para>
|
||||||
|
If set to true, mac and dos newlines (\r and \r\n) in config files are
|
||||||
|
converted to \n when they are parsed. true by default.
|
||||||
|
</para>
|
||||||
|
</sect1>
|
||||||
<sect1 id="variable.default.template.handler.func">
|
<sect1 id="variable.default.template.handler.func">
|
||||||
<title>$default_template_handler_func</title>
|
<title>$default_template_handler_func</title>
|
||||||
<para>
|
<para>
|
||||||
@@ -701,6 +734,64 @@ $smarty->clear_compiled_tpl("index.tpl");
|
|||||||
|
|
||||||
// clear entire compile directory
|
// clear entire compile directory
|
||||||
$smarty->clear_compiled_tpl();</programlisting>
|
$smarty->clear_compiled_tpl();</programlisting>
|
||||||
|
</example>
|
||||||
|
</sect1>
|
||||||
|
<sect1 id="api.clear.config">
|
||||||
|
<title>clear_config</title>
|
||||||
|
<funcsynopsis>
|
||||||
|
<funcprototype>
|
||||||
|
<funcdef>void <function>clear_config</function></funcdef>
|
||||||
|
<paramdef>string <parameter><optional>var</optional></parameter></paramdef>
|
||||||
|
</funcprototype>
|
||||||
|
</funcsynopsis>
|
||||||
|
<para>
|
||||||
|
This clears all assigned config variables. If a variable name is
|
||||||
|
supplied, only that variable is cleared.
|
||||||
|
</para>
|
||||||
|
<example>
|
||||||
|
<title>clear_config</title>
|
||||||
|
<programlisting>
|
||||||
|
// clear all assigned config variables.
|
||||||
|
$smarty->clear_config();
|
||||||
|
|
||||||
|
// clear one variable
|
||||||
|
$smarty->clear_config('foobar');</programlisting>
|
||||||
|
</example>
|
||||||
|
</sect1>
|
||||||
|
<sect1 id="api.config.load">
|
||||||
|
<title>config_load</title>
|
||||||
|
<funcsynopsis>
|
||||||
|
<funcprototype>
|
||||||
|
<funcdef>void <function>config_load</function></funcdef>
|
||||||
|
<paramdef>string <parameter>file</parameter></paramdef>
|
||||||
|
<paramdef>string <parameter><optional>section</optional></parameter></paramdef>
|
||||||
|
</funcprototype>
|
||||||
|
</funcsynopsis>
|
||||||
|
<para>
|
||||||
|
This loads config file data and assigns it to the template. This
|
||||||
|
works identical to the template <link
|
||||||
|
linkend="language.function.config.load">config_load</link>
|
||||||
|
function.
|
||||||
|
</para>
|
||||||
|
<note>
|
||||||
|
<title>Technical Note</title>
|
||||||
|
<para>
|
||||||
|
As of Smarty 2.4.0, assigned template variables are kept across
|
||||||
|
invocations of fetch() and display(). Config vars loaded from
|
||||||
|
config_load() are always global scope. Config files are also
|
||||||
|
compiled for faster execution, and respect the <link
|
||||||
|
linkend="variable.force.compile">force_compile</link> and <link
|
||||||
|
linkend="variable.compile.check">compile_check</link> settings.
|
||||||
|
</para>
|
||||||
|
</note>
|
||||||
|
<example>
|
||||||
|
<title>config_load</title>
|
||||||
|
<programlisting>
|
||||||
|
// load config variables and assign them
|
||||||
|
$smarty->config_load('my.conf');
|
||||||
|
|
||||||
|
// load a section
|
||||||
|
$smarty->config_load('my.conf','foobar');</programlisting>
|
||||||
</example>
|
</example>
|
||||||
</sect1>
|
</sect1>
|
||||||
<sect1 id="api.display">
|
<sect1 id="api.display">
|
||||||
|
Reference in New Issue
Block a user