mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-05 19:04:27 +02:00
update RELEASE_NOTES & scripts with new section var syntax
This commit is contained in:
12
QUICKSTART
12
QUICKSTART
@@ -178,7 +178,7 @@ $smarty->display("index.tpl");
|
|||||||
|
|
||||||
--------- templates/header.tpl --------
|
--------- templates/header.tpl --------
|
||||||
<HTML>
|
<HTML>
|
||||||
<TITLE>{$title|default:"no title"}</TITLE>
|
<TITLE>{$title}</TITLE>
|
||||||
<BODY>
|
<BODY>
|
||||||
|
|
||||||
--------- templates/footer.tpl --------
|
--------- templates/footer.tpl --------
|
||||||
@@ -191,7 +191,7 @@ You can pass as many variables as you want. The included file inherits all the
|
|||||||
current template vars, plus any that are passed to it. The passed variables are
|
current template vars, plus any that are passed to it. The passed variables are
|
||||||
only available within the scope of the included file. Also notice the way the
|
only available within the scope of the included file. Also notice the way the
|
||||||
$title variable is printed to the template. It uses a variable modifier called
|
$title variable is printed to the template. It uses a variable modifier called
|
||||||
"default". Printing {$title|default:"no title"} means that if the value of
|
"default". Printing {$title} means that if the value of
|
||||||
$title is empty, the text "no title" will be printed instead of nothing.
|
$title is empty, the text "no title" will be printed instead of nothing.
|
||||||
|
|
||||||
IF/ELSEIF/ELSE
|
IF/ELSEIF/ELSE
|
||||||
@@ -236,7 +236,7 @@ $smarty->display("index.tpl");
|
|||||||
--------- templates/index.tpl --------
|
--------- templates/index.tpl --------
|
||||||
{include file="header.tpl" title="Home Page"}
|
{include file="header.tpl" title="Home Page"}
|
||||||
{section name=people loop=$FirstName}
|
{section name=people loop=$FirstName}
|
||||||
{%people.rownum%} {$people/FirstName} {$people/LastName}<br>
|
{%people.rownum%} {$FirstName[people]} {$LastName[people]}<br>
|
||||||
{sectionelse}
|
{sectionelse}
|
||||||
There are no values to loop through.
|
There are no values to loop through.
|
||||||
{/section}
|
{/section}
|
||||||
@@ -278,11 +278,11 @@ $smarty->display("index.tpl");
|
|||||||
--------- templates/index.tpl --------
|
--------- templates/index.tpl --------
|
||||||
{include file="header.tpl" title="Home Page"}
|
{include file="header.tpl" title="Home Page"}
|
||||||
{section name=people loop=$FirstName}
|
{section name=people loop=$FirstName}
|
||||||
{%people.rownum%} {$people/FirstName} {$people/LastName}<br>
|
{%people.rownum%} {$FirstName[people]} {$LastName[people]}<br>
|
||||||
{section name=contacts loop=$people/ContactNames}
|
{section name=contacts loop=$ContactNames[people]}
|
||||||
{* for fun, lets bold every other row *}
|
{* for fun, lets bold every other row *}
|
||||||
{if %contacts.rownum% is even}<b>{/if}
|
{if %contacts.rownum% is even}<b>{/if}
|
||||||
{$people/contacts/ContactNames}: {$people/contacts/ContactVals}<br>
|
{$ContactNames[people][contacts]}: {$ContactVals[people][contacts]}<br>
|
||||||
{if %contacts.rownum% is even}</b>{/if}
|
{if %contacts.rownum% is even}</b>{/if}
|
||||||
{/section}
|
{/section}
|
||||||
<br>
|
<br>
|
||||||
|
@@ -1,17 +1,29 @@
|
|||||||
1.4.0
|
1.4.0
|
||||||
-----
|
-----
|
||||||
|
|
||||||
The most significant change to Smarty 1.4.0 is the compilation process. Instead
|
IMPORTANT NOTICE: Smarty now has a new syntax for accessing elements within
|
||||||
of compiling all the templates up front, it now compiles them at runtime. This
|
section loops. The new syntax is easier to use for complex data structures.
|
||||||
has several advantages. First off, there is no longer a need to have a single
|
Consequently, this breaks the old syntax. To fix your old templates, we have
|
||||||
template directory. You can now have arbitrary template sources, such as
|
provided a script that will fix the syntax for you. Located in
|
||||||
multiple directories or even database calls. This also speeds the performance
|
misc/fix_vars.php, run this script from the the command line, giving each
|
||||||
of Smarty when $compile_check is enabled, since it is only checking the
|
template as an argument. Be sure to use absolute pathnames, or pathnames
|
||||||
template that is being executed instead of everything found in the template
|
relative to the executing script. Probably the easiest way to do this is to
|
||||||
directory. The $tpl_file_ext is no longer needed, but kept for backward
|
copy the fix_vars.php script into your template directory and run 'php -q
|
||||||
compatability. Templates can now be named anything you like with any extension.
|
fix_vars.php *.tpl' For each template, this will create a temporary file with
|
||||||
Smarty makes use of the PEAR database abstraction class for obtaining templates
|
the fixes, then move the temp file over top the original. Backup your scripts
|
||||||
from databases.
|
first to be safe!
|
||||||
|
|
||||||
|
Smarty 1.4.0 also has a new compilation process. Instead of compiling all the
|
||||||
|
templates up front, it now compiles them at runtime. This has several
|
||||||
|
advantages. First of all, there is no longer a need to have a single template
|
||||||
|
directory. You can now have arbitrary template sources, such as multiple
|
||||||
|
directories or even database calls. This also speeds the performance of Smarty
|
||||||
|
when $compile_check is enabled, since it is only checking the template that is
|
||||||
|
being executed instead of everything found in the template directory. The
|
||||||
|
$tpl_file_ext is no longer needed, but kept for backward compatability.
|
||||||
|
Templates can now be named anything you like with any extension. Smarty makes
|
||||||
|
use of the PEAR database abstraction class for obtaining templates from
|
||||||
|
databases.
|
||||||
|
|
||||||
We also added a workaround for LOCK_EX on Windows systems, and changed a couple
|
We also added a workaround for LOCK_EX on Windows systems, and changed a couple
|
||||||
of file permissions for better security on public servers. Thanks goes to
|
of file permissions for better security on public servers. Thanks goes to
|
||||||
|
@@ -12,14 +12,14 @@ Title: {#title#|capitalize}
|
|||||||
the value of $SCRIPT_NAME is {$SCRIPT_NAME}
|
the value of $SCRIPT_NAME is {$SCRIPT_NAME}
|
||||||
|
|
||||||
{* A simple variable test. print $Name in uppercase *}
|
{* A simple variable test. print $Name in uppercase *}
|
||||||
hello, my name is {$Name|upper}
|
hello, my name is {$Name}
|
||||||
|
|
||||||
My interests are:
|
My interests are:
|
||||||
{section name=outer loop=$FirstName}
|
{section name=outer loop=$FirstName}
|
||||||
{if %outer.index% is odd by 2}
|
{if %outer.index% is odd by 2}
|
||||||
{%outer.rownum%} . {$outer/FirstName} {$outer/LastName}
|
{%outer.rownum%} . {$FirstName[outer]} {$LastName[outer]}
|
||||||
{else}
|
{else}
|
||||||
{%outer.rownum%} * {$outer/FirstName} {$outer/LastName}
|
{%outer.rownum%} * {$FirstName[outer]} {$LastName[outer]}
|
||||||
{/if}
|
{/if}
|
||||||
{sectionelse}
|
{sectionelse}
|
||||||
none
|
none
|
||||||
@@ -27,9 +27,9 @@ My interests are:
|
|||||||
|
|
||||||
testing section looped key values<br>
|
testing section looped key values<br>
|
||||||
{section name=sec1 loop=$contacts}
|
{section name=sec1 loop=$contacts}
|
||||||
phone: {$sec1/contacts.phone}<br>
|
phone: {$contacts[sec1].phone}<br>
|
||||||
fax: {$sec1/contacts.fax}<br>
|
fax: {$contacts[sec1].fax}<br>
|
||||||
cell: {$sec1/contacts.cell}<br>
|
cell: {$contacts[sec1].cell}<br>
|
||||||
{/section}
|
{/section}
|
||||||
<p>
|
<p>
|
||||||
|
|
||||||
|
264
docs.sgml
264
docs.sgml
@@ -709,7 +709,7 @@ $smarty->unregister_modifier("fetch");
|
|||||||
|
|
||||||
$smarty->register_modifier("sslash","stripslashes");
|
$smarty->register_modifier("sslash","stripslashes");
|
||||||
|
|
||||||
// now you can use {$var|sslash} to strip slashes from variables
|
// now you can use {$var} to strip slashes from variables
|
||||||
|
|
||||||
</programlisting>
|
</programlisting>
|
||||||
</example>
|
</example>
|
||||||
@@ -1689,9 +1689,9 @@ OUTPUT:
|
|||||||
section names must be unique from each other. The loop variable
|
section names must be unique from each other. The loop variable
|
||||||
(usually an array of values) determines the number of times the
|
(usually an array of values) determines the number of times the
|
||||||
section will loop. When printing a variable within a section, the
|
section will loop. When printing a variable within a section, the
|
||||||
section name must be prepended to the variable name, separated by a
|
section name must be given next to variable name within brackets
|
||||||
slash (/). If you are using an associative array, separate the key
|
[]. If you are using an associative array, separate the key and
|
||||||
and value with a period (.). <emphasis>sectionelse</emphasis> is
|
value with a period (.). <emphasis>sectionelse</emphasis> is
|
||||||
executed when there are no values in the loop variable.
|
executed when there are no values in the loop variable.
|
||||||
</para>
|
</para>
|
||||||
<example>
|
<example>
|
||||||
@@ -1701,7 +1701,7 @@ OUTPUT:
|
|||||||
|
|
||||||
{* this example will print out all the values of the $custid array *}
|
{* this example will print out all the values of the $custid array *}
|
||||||
{section name=customer loop=$custid}
|
{section name=customer loop=$custid}
|
||||||
id: {$customer/custid}<br>
|
id: {$custid[customer]}<br>
|
||||||
{/section}
|
{/section}
|
||||||
|
|
||||||
OUTPUT:
|
OUTPUT:
|
||||||
@@ -1722,9 +1722,9 @@ id: 1002<br>
|
|||||||
This example assumes that $custid, $name and $address are all
|
This example assumes that $custid, $name and $address are all
|
||||||
arrays containing the same number of values *}
|
arrays containing the same number of values *}
|
||||||
{section name=customer loop=$custid}
|
{section name=customer loop=$custid}
|
||||||
id: {$customer/custid}<br>
|
id: {$custid[customer]}<br>
|
||||||
name: {$customer/name}<br>
|
name: {$name[customer]}<br>
|
||||||
address: {$customer/address}<br>
|
address: {$address[customer]}<br>
|
||||||
<p>
|
<p>
|
||||||
{/section}
|
{/section}
|
||||||
|
|
||||||
@@ -1754,9 +1754,9 @@ address: 5605 apple st<br>
|
|||||||
{* the name of the section can be anything you like,
|
{* the name of the section can be anything you like,
|
||||||
and it is used to reference the data within the section *}
|
and it is used to reference the data within the section *}
|
||||||
{section name=mydata loop=$custid}
|
{section name=mydata loop=$custid}
|
||||||
id: {$mydata/custid}<br>
|
id: {$custid[mydata]}<br>
|
||||||
name: {$mydata/name}<br>
|
name: {$name[mydata]}<br>
|
||||||
address: {$mydata/address}<br>
|
address: {$address[mydata]}<br>
|
||||||
<p>
|
<p>
|
||||||
{/section}
|
{/section}
|
||||||
|
|
||||||
@@ -1769,14 +1769,14 @@ address: 5605 apple st<br>
|
|||||||
|
|
||||||
{* sections can be nested as deep as you like. With nested sections,
|
{* sections can be nested as deep as you like. With nested sections,
|
||||||
you can access complex data structures, such as multi-dimensional
|
you can access complex data structures, such as multi-dimensional
|
||||||
arrays. In this example, $customer/contact_type is an array of
|
arrays. In this example, $contact_type[customer] is an array of
|
||||||
contact types for the current customer. *}
|
contact types for the current customer. *}
|
||||||
{section name=customer loop=$custid}
|
{section name=customer loop=$custid}
|
||||||
id: {$customer/custid}<br>
|
id: {$custid[customer]}<br>
|
||||||
name: {$customer/name}<br>
|
name: {$name[customer]}<br>
|
||||||
address: {$customer/address}<br>
|
address: {$address[customer]}<br>
|
||||||
{section name=contact loop=$customer/contact_type}
|
{section name=contact loop=$contact_type[customer]}
|
||||||
{$customer/contact/contact_type}: {$customer/contact/contact_info}<br>
|
{$contact_type[customer][contact]}: {$contact_info[customer][contact]}<br>
|
||||||
{/section}
|
{/section}
|
||||||
<p>
|
<p>
|
||||||
{/section}
|
{/section}
|
||||||
@@ -1817,10 +1817,10 @@ e-mail: jane@mydomain.com<br>
|
|||||||
{* This is an example of printing an associative array
|
{* This is an example of printing an associative array
|
||||||
of data within a section *}
|
of data within a section *}
|
||||||
{section name=customer loop=$contacts}
|
{section name=customer loop=$contacts}
|
||||||
name: {$customer/contacts.name}<br>
|
name: {$contacts[customer].name}<br>
|
||||||
home: {$customer/contacts.home}<br>
|
home: {$contacts[customer].home}<br>
|
||||||
cell: {$customer/contacts.cell}<br>
|
cell: {$contacts[customer].cell}<br>
|
||||||
e-mail: {$customer/contacts.email}<p>
|
e-mail: {$contacts[customer].email}<p>
|
||||||
{/section}
|
{/section}
|
||||||
|
|
||||||
|
|
||||||
@@ -1851,7 +1851,7 @@ e-mail: jane@mydomain.com<p>
|
|||||||
|
|
||||||
{* sectionelse will execute if there are no $custid values *}
|
{* sectionelse will execute if there are no $custid values *}
|
||||||
{section name=customer loop=$custid}
|
{section name=customer loop=$custid}
|
||||||
id: {$customer/custid}<br>
|
id: {$custid[customer]}<br>
|
||||||
{sectionelse}
|
{sectionelse}
|
||||||
there are no values in $custid.
|
there are no values in $custid.
|
||||||
{/section}
|
{/section}
|
||||||
@@ -1873,7 +1873,7 @@ e-mail: jane@mydomain.com<p>
|
|||||||
<title>section property index</title>
|
<title>section property index</title>
|
||||||
<programlisting>
|
<programlisting>
|
||||||
{section name=customer loop=$custid}
|
{section name=customer loop=$custid}
|
||||||
{%customer.index%} id: {$customer/custid}<br>
|
{%customer.index%} id: {$custid[customer]}<br>
|
||||||
{/section}
|
{/section}
|
||||||
|
|
||||||
|
|
||||||
@@ -1896,9 +1896,9 @@ OUTPUT:
|
|||||||
<title>section property index_prev</title>
|
<title>section property index_prev</title>
|
||||||
<programlisting>
|
<programlisting>
|
||||||
{section name=customer loop=$custid}
|
{section name=customer loop=$custid}
|
||||||
{%customer.index%} id: {$customer/custid}<br>
|
{%customer.index%} id: {$custid[customer]}<br>
|
||||||
{* FYI, $customer.index/custid and $customer/custid are identical in meaning *}
|
{* FYI, $custid[customer.index] and $custid[customer] are identical in meaning *}
|
||||||
{if $customer.index_prev/custid ne $customer.index/custid}
|
{if $custid[customer.index_prev] ne $custid[customer.index]}
|
||||||
The customer id changed<br>
|
The customer id changed<br>
|
||||||
{/if}
|
{/if}
|
||||||
{/section}
|
{/section}
|
||||||
@@ -1926,9 +1926,9 @@ OUTPUT:
|
|||||||
<title>section property index_next</title>
|
<title>section property index_next</title>
|
||||||
<programlisting>
|
<programlisting>
|
||||||
{section name=customer loop=$custid}
|
{section name=customer loop=$custid}
|
||||||
{%customer.index%} id: {$customer/custid}<br>
|
{%customer.index%} id: {$custid[customer]}<br>
|
||||||
{* FYI, $customer.index/custid and $customer/custid are identical in meaning *}
|
{* FYI, $custid[customer.index] and $custid[customer] are identical in meaning *}
|
||||||
{if $customer.index_next/custid ne $customer.index/custid}
|
{if $custid[customer.index_next] ne $custid[customer.index]}
|
||||||
The customer id will change<br>
|
The customer id will change<br>
|
||||||
{/if}
|
{/if}
|
||||||
{/section}
|
{/section}
|
||||||
@@ -1961,7 +1961,7 @@ OUTPUT:
|
|||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<tr><td>{%customer.index%} id:
|
<tr><td>{%customer.index%} id:
|
||||||
{$customer/custid}</td></tr>
|
{$custid[customer]}</td></tr>
|
||||||
|
|
||||||
{if %customer.last%}
|
{if %customer.last%}
|
||||||
</table>
|
</table>
|
||||||
@@ -1995,7 +1995,7 @@ OUTPUT:
|
|||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<tr><td>{%customer.index%} id:
|
<tr><td>{%customer.index%} id:
|
||||||
{$customer/custid}</td></tr>
|
{$custid[customer]}</td></tr>
|
||||||
|
|
||||||
{if %customer.last%}
|
{if %customer.last%}
|
||||||
</table>
|
</table>
|
||||||
@@ -2024,7 +2024,7 @@ OUTPUT:
|
|||||||
<title>section property rownum</title>
|
<title>section property rownum</title>
|
||||||
<programlisting>
|
<programlisting>
|
||||||
{section name=customer loop=$custid}
|
{section name=customer loop=$custid}
|
||||||
{%customer.rownum%} id: {$customer/custid}<br>
|
{%customer.rownum%} id: {$custid[customer]}<br>
|
||||||
{/section}
|
{/section}
|
||||||
|
|
||||||
|
|
||||||
@@ -2048,7 +2048,7 @@ OUTPUT:
|
|||||||
<title>section property index</title>
|
<title>section property index</title>
|
||||||
<programlisting>
|
<programlisting>
|
||||||
{section name=customer loop=$custid}
|
{section name=customer loop=$custid}
|
||||||
{%customer.index%} id: {$customer/custid}<br>
|
{%customer.index%} id: {$custid[customer]}<br>
|
||||||
{/section}
|
{/section}
|
||||||
|
|
||||||
There were {%customer.loop%} customers shown above.
|
There were {%customer.loop%} customers shown above.
|
||||||
@@ -2078,7 +2078,7 @@ There were 3 customers shown above.
|
|||||||
{* $show_customer_info may have been passed from the PHP
|
{* $show_customer_info may have been passed from the PHP
|
||||||
application, to regulate whether or not this section shows *}
|
application, to regulate whether or not this section shows *}
|
||||||
{section name=customer loop=$custid show=$show_customer_info}
|
{section name=customer loop=$custid show=$show_customer_info}
|
||||||
{%customer.rownum%} id: {$customer/custid}<br>
|
{%customer.rownum%} id: {$custid[customer]}<br>
|
||||||
{/section}
|
{/section}
|
||||||
|
|
||||||
{if %customer.show%}
|
{if %customer.show%}
|
||||||
@@ -2921,7 +2921,7 @@ OUTPUT:
|
|||||||
NOTE: if you apply a modifier to an array instead of a single value
|
NOTE: if you apply a modifier to an array instead of a single value
|
||||||
variable, the modifier will be applied to every value in that array. If
|
variable, the modifier will be applied to every value in that array. If
|
||||||
you really want the entire array passed to the modifier, you must
|
you really want the entire array passed to the modifier, you must
|
||||||
prepend it with an "@" sign like so: {$articleTitle|@count} (this will
|
prepend it with an "@" sign like so: {$articleTitle} (this will
|
||||||
print out the number of elements in the $articleTitle array.)
|
print out the number of elements in the $articleTitle array.)
|
||||||
</para>
|
</para>
|
||||||
<sect2>
|
<sect2>
|
||||||
@@ -2934,7 +2934,7 @@ OUTPUT:
|
|||||||
<programlisting>
|
<programlisting>
|
||||||
|
|
||||||
{$articleTitle}
|
{$articleTitle}
|
||||||
{$articleTitle|capitalize}
|
{$articleTitle}
|
||||||
|
|
||||||
OUTPUT:
|
OUTPUT:
|
||||||
|
|
||||||
@@ -2955,7 +2955,7 @@ Police Begin Campaign To Rundown Jaywalkers.
|
|||||||
|
|
||||||
|
|
||||||
{$articleTitle}
|
{$articleTitle}
|
||||||
{$articleTitle|count_characters}
|
{$articleTitle}
|
||||||
|
|
||||||
OUTPUT:
|
OUTPUT:
|
||||||
|
|
||||||
@@ -2976,7 +2976,7 @@ Cold Wave Linked to Temperatures
|
|||||||
|
|
||||||
|
|
||||||
{$articleTitle}
|
{$articleTitle}
|
||||||
{$articleTitle|count_paragraphs}
|
{$articleTitle}
|
||||||
|
|
||||||
OUTPUT:
|
OUTPUT:
|
||||||
|
|
||||||
@@ -2999,7 +2999,7 @@ Man is Fatally Slain. Death Causes Loneliness, Feeling of Isolation.
|
|||||||
|
|
||||||
|
|
||||||
{$articleTitle}
|
{$articleTitle}
|
||||||
{$articleTitle|count_sentences}
|
{$articleTitle}
|
||||||
|
|
||||||
OUTPUT:
|
OUTPUT:
|
||||||
|
|
||||||
@@ -3020,7 +3020,7 @@ Two Soviet Ships Collide - One Dies. Enraged Cow Injures Farmer with Axe.
|
|||||||
|
|
||||||
|
|
||||||
{$articleTitle}
|
{$articleTitle}
|
||||||
{$articleTitle|count_words}
|
{$articleTitle}
|
||||||
|
|
||||||
OUTPUT:
|
OUTPUT:
|
||||||
|
|
||||||
@@ -3070,9 +3070,9 @@ Dealers Will Hear Car Talk at Noon.
|
|||||||
<title>date_format</title>
|
<title>date_format</title>
|
||||||
<programlisting>
|
<programlisting>
|
||||||
|
|
||||||
{$currentDate|date_format}
|
{$currentDate}
|
||||||
{$currentDate|date_format:"%A, %B %e, %Y"}
|
{$currentDate}
|
||||||
{$currentDate|date_format:"%H:%M:%S"}
|
{$currentDate}
|
||||||
|
|
||||||
OUTPUT:
|
OUTPUT:
|
||||||
|
|
||||||
@@ -3211,7 +3211,7 @@ system's manpage for a full list of valid specifiers.
|
|||||||
<programlisting>
|
<programlisting>
|
||||||
|
|
||||||
{* this will display "no title" (without the quotes) if $articleTitle is empty *}
|
{* this will display "no title" (without the quotes) if $articleTitle is empty *}
|
||||||
{$articleTitle|default:"no title"}
|
{$articleTitle}
|
||||||
|
|
||||||
OUTPUT:
|
OUTPUT:
|
||||||
|
|
||||||
@@ -3261,9 +3261,9 @@ no title
|
|||||||
<programlisting>
|
<programlisting>
|
||||||
|
|
||||||
{$articleTitle}
|
{$articleTitle}
|
||||||
{$articleTitle|escape}
|
{$articleTitle}
|
||||||
{$articleTitle|escape:"html"}
|
{$articleTitle}
|
||||||
{$articleTitle|escape:"url"}
|
{$articleTitle}
|
||||||
|
|
||||||
OUTPUT:
|
OUTPUT:
|
||||||
|
|
||||||
@@ -3285,7 +3285,7 @@ Stiff+Opposition+Expected+to+Casketless+Funeral+Plan
|
|||||||
<programlisting>
|
<programlisting>
|
||||||
|
|
||||||
{$articleTitle}
|
{$articleTitle}
|
||||||
{$articleTitle|lower}
|
{$articleTitle}
|
||||||
|
|
||||||
OUTPUT:
|
OUTPUT:
|
||||||
|
|
||||||
@@ -3339,8 +3339,8 @@ two convicts evade noose, jury hung.
|
|||||||
<programlisting>
|
<programlisting>
|
||||||
|
|
||||||
{$articleTitle}
|
{$articleTitle}
|
||||||
{$articleTitle|replace:"Garden":"Vineyard"}
|
{$articleTitle}
|
||||||
{$articleTitle|replace:" ":" "}
|
{$articleTitle}
|
||||||
|
|
||||||
OUTPUT:
|
OUTPUT:
|
||||||
|
|
||||||
@@ -3390,8 +3390,8 @@ Child's Stool Great for Use in Garden.
|
|||||||
<programlisting>
|
<programlisting>
|
||||||
|
|
||||||
{$articleTitle}
|
{$articleTitle}
|
||||||
{$articleTitle|spacify}
|
{$articleTitle}
|
||||||
{$articleTitle|spacify:"^^"}
|
{$articleTitle}
|
||||||
|
|
||||||
OUTPUT:
|
OUTPUT:
|
||||||
|
|
||||||
@@ -3440,8 +3440,8 @@ S^^o^^m^^e^^t^^h^^i^^n^^g^^ ^^W^^e^^n^^t^^ ^^W^^r^^o^^n^^g^^ ^^i^^n^^ ^^J^^e^^t^
|
|||||||
<programlisting>
|
<programlisting>
|
||||||
|
|
||||||
{$number}
|
{$number}
|
||||||
{$number|string_format:"%.2f"}
|
{$number}
|
||||||
{$number|string_format:"%d"}
|
{$number}
|
||||||
|
|
||||||
OUTPUT:
|
OUTPUT:
|
||||||
|
|
||||||
@@ -3462,7 +3462,7 @@ OUTPUT:
|
|||||||
<programlisting>
|
<programlisting>
|
||||||
|
|
||||||
{$articleTitle}
|
{$articleTitle}
|
||||||
{$articleTitle|strip_tags}
|
{$articleTitle}
|
||||||
|
|
||||||
OUTPUT:
|
OUTPUT:
|
||||||
|
|
||||||
@@ -3531,37 +3531,8 @@ Blind Woman Gets New Kidney from Dad she Hasn't Seen in years.
|
|||||||
<programlisting>
|
<programlisting>
|
||||||
|
|
||||||
{$articleTitle}
|
{$articleTitle}
|
||||||
{$articleTitle|truncate}
|
|
||||||
{$articleTitle|truncate:30}
|
|
||||||
{$articleTitle|truncate:30:""}
|
|
||||||
{$articleTitle|truncate:30:"---"}
|
|
||||||
{$articleTitle|truncate:30:"":true}
|
|
||||||
{$articleTitle|truncate:30:"...":true}
|
|
||||||
|
|
||||||
OUTPUT:
|
|
||||||
|
|
||||||
Two Sisters Reunite after Eighteen Years at Checkout Counter.
|
|
||||||
Two Sisters Reunite after Eighteen Years at Checkout Counter.
|
|
||||||
Two Sisters Reunite after...
|
|
||||||
Two Sisters Reunite after
|
|
||||||
Two Sisters Reunite after---
|
|
||||||
Two Sisters Reunite after Eigh
|
|
||||||
Two Sisters Reunite after E...
|
|
||||||
|
|
||||||
</programlisting>
|
|
||||||
</example>
|
|
||||||
</sect2>
|
|
||||||
<sect2>
|
|
||||||
<title>upper</title>
|
|
||||||
<para>
|
|
||||||
This is used to uppercase a variable.
|
|
||||||
</para>
|
|
||||||
<example>
|
|
||||||
<title>upper</title>
|
|
||||||
<programlisting>
|
|
||||||
|
|
||||||
{$articleTitle}
|
{$articleTitle}
|
||||||
{$articleTitle|upper}
|
{$articleTitle}
|
||||||
|
|
||||||
OUTPUT:
|
OUTPUT:
|
||||||
|
|
||||||
@@ -3584,129 +3555,17 @@ IF STRIKE ISN'T SETTLED QUICKLY IT MAY LAST A WHILE.
|
|||||||
<programlisting>
|
<programlisting>
|
||||||
|
|
||||||
{$articleTitle}
|
{$articleTitle}
|
||||||
{$articleTitle|upper|spacify}
|
{$articleTitle}
|
||||||
{$articleTitle|lower|spacify|truncate}
|
{$articleTitle}
|
||||||
{$articleTitle|lower|truncate:30|spacify}
|
{$articleTitle}
|
||||||
{$articleTitle|lower|spacify|truncate:30:". . ."}
|
{$articleTitle}
|
||||||
|
|
||||||
OUTPUT:
|
|
||||||
|
|
||||||
Smokers are Productive, but Death Cuts Efficiency.
|
|
||||||
S M O K E R S A R E P R O D U C T I V E , B U T D E A T H C U T S E F F I C I E N C Y .
|
|
||||||
s m o k e r s a r e p r o d u c t i v e , b u t d e a t h c u t s...
|
|
||||||
s m o k e r s a r e p r o d u c t i v e , b u t . . .
|
|
||||||
s m o k e r s a r e p. . .
|
|
||||||
|
|
||||||
</programlisting>
|
|
||||||
</example>
|
|
||||||
</sect2>
|
|
||||||
<sect2>
|
|
||||||
<title>Creating your own Variable Modifiers</title>
|
|
||||||
<para>
|
|
||||||
Creating your own modifiers is a fairly straight forward process.
|
|
||||||
The best way is to look at the ones that come with Smarty as
|
|
||||||
examples. The function names begin with smarty_mod_ and they are
|
|
||||||
located in the Smarty.addons.php file.
|
|
||||||
</para>
|
|
||||||
<itemizedlist>
|
|
||||||
<listitem><para>add your modifier to the Smarty.addons.php file.
|
|
||||||
It is recommended that you prepend your function name
|
|
||||||
with smarty_mod_</para></listitem>
|
|
||||||
<listitem><para>map a template modifier name to your PHP function.
|
|
||||||
This is done at the top of the Smarty.class.php file
|
|
||||||
in the $custom_mods array.</para></listitem>
|
|
||||||
<listitem><para>Thats it! you can now use that modifier
|
|
||||||
from within Smarty.</para></listitem>
|
|
||||||
</itemizedlist>
|
|
||||||
<para>
|
|
||||||
You can also add modifiers programatically with the <link
|
|
||||||
linkend="api.register.modifier">register_modifier API</link>.
|
|
||||||
</para>
|
|
||||||
</sect2>
|
|
||||||
</sect1>
|
|
||||||
</chapter>
|
|
||||||
<chapter>
|
|
||||||
<title>Troubleshooting</title>
|
|
||||||
<para></para>
|
|
||||||
<sect1>
|
|
||||||
<title>Smarty/PHP errors</title>
|
|
||||||
<para>
|
|
||||||
Smarty can catch many errors such as missing tag attributes
|
|
||||||
or malformed variable names. If this happens, you will see an error
|
|
||||||
similar to the following:
|
|
||||||
</para>
|
|
||||||
|
|
||||||
<example>
|
|
||||||
<title>Smarty errors</title>
|
|
||||||
<programlisting>
|
|
||||||
|
|
||||||
Warning: Smarty: [in index.tpl line 4]: syntax error: unknown tag - '%blah'
|
|
||||||
in /path/to/smarty/Smarty.class.php on line 1041
|
|
||||||
|
|
||||||
Fatal error: Smarty: [in index.tpl line 28]: syntax error: missing section name
|
|
||||||
in /path/to/smarty/Smarty.class.php on line 1041
|
|
||||||
|
|
||||||
</programlisting>
|
|
||||||
</example>
|
|
||||||
|
|
||||||
<para>
|
|
||||||
Smarty shows you the template name, the line number and the error.
|
|
||||||
After that, the error consists of the actual line number in the Smarty
|
|
||||||
class that the error occured.
|
|
||||||
</para>
|
|
||||||
|
|
||||||
<para>
|
|
||||||
There are certain errors that Smarty cannot catch, such as missing
|
|
||||||
close tags. These types of errors usually end up in PHP compile-time
|
|
||||||
parsing errors.
|
|
||||||
</para>
|
|
||||||
|
|
||||||
<example>
|
|
||||||
<title>PHP parsing errors</title>
|
|
||||||
<programlisting>
|
|
||||||
|
|
||||||
Parse error: parse error in /path/to/smarty/templates_c/index.tpl.php on line 75
|
|
||||||
|
|
||||||
</programlisting>
|
|
||||||
</example>
|
|
||||||
|
|
||||||
<para>
|
|
||||||
When you encounter a PHP parsing error, the error line number will
|
|
||||||
correspond to the compiled PHP script, not the template itself. Usually
|
|
||||||
you can look at the template and spot the syntax error. Here are some
|
|
||||||
common things to look for: missing close tags for {if}{/if} or
|
|
||||||
{section}{/section}, or syntax of logic within an {if} tag. If you
|
|
||||||
can't find the error, you might have to open the compiled PHP file and
|
|
||||||
go to the line number to figure out where the corresponding error is in
|
|
||||||
the template.
|
|
||||||
</para>
|
|
||||||
</sect1>
|
|
||||||
</chapter>
|
|
||||||
<chapter id="tips">
|
|
||||||
<title>Tips & Tricks</title>
|
|
||||||
<para>
|
|
||||||
</para>
|
|
||||||
<sect1>
|
|
||||||
<title>Dates</title>
|
|
||||||
<para>
|
|
||||||
Dates can be passed to Smarty as unix timestamps, mysql timestamps,
|
|
||||||
or a parsable string made of month day and year (parsable by strtotime())
|
|
||||||
This allows template designers to use <link
|
|
||||||
linkend="date.format">date_format</link> for full control over date
|
|
||||||
formatting, and also makes it easy to compare dates if necessary.
|
|
||||||
</para>
|
|
||||||
<example>
|
|
||||||
<title>using date_format</title>
|
|
||||||
<programlisting>
|
|
||||||
|
|
||||||
{$startDate|date_format}
|
|
||||||
|
|
||||||
OUTPUT:
|
OUTPUT:
|
||||||
|
|
||||||
Jan 4, 2001
|
Jan 4, 2001
|
||||||
|
|
||||||
|
|
||||||
{$startDate|date_format:"%Y/%m/%d"}
|
{$startDate}
|
||||||
|
|
||||||
OUTPUT:
|
OUTPUT:
|
||||||
|
|
||||||
@@ -3747,6 +3606,7 @@ function makeTimeStamp($year="",$month="",$day="")
|
|||||||
|
|
||||||
</programlisting>
|
</programlisting>
|
||||||
</example>
|
</example>
|
||||||
|
</sect2>
|
||||||
</sect1>
|
</sect1>
|
||||||
</chapter>
|
</chapter>
|
||||||
<chapter id="resources">
|
<chapter id="resources">
|
||||||
|
@@ -12,14 +12,14 @@ Title: {#title#|capitalize}
|
|||||||
the value of $SCRIPT_NAME is {$SCRIPT_NAME}
|
the value of $SCRIPT_NAME is {$SCRIPT_NAME}
|
||||||
|
|
||||||
{* A simple variable test. print $Name in uppercase *}
|
{* A simple variable test. print $Name in uppercase *}
|
||||||
hello, my name is {$Name|upper}
|
hello, my name is {$Name}
|
||||||
|
|
||||||
My interests are:
|
My interests are:
|
||||||
{section name=outer loop=$FirstName}
|
{section name=outer loop=$FirstName}
|
||||||
{if %outer.index% is odd by 2}
|
{if %outer.index% is odd by 2}
|
||||||
{%outer.rownum%} . {$outer/FirstName} {$outer/LastName}
|
{%outer.rownum%} . {$FirstName[outer]} {$LastName[outer]}
|
||||||
{else}
|
{else}
|
||||||
{%outer.rownum%} * {$outer/FirstName} {$outer/LastName}
|
{%outer.rownum%} * {$FirstName[outer]} {$LastName[outer]}
|
||||||
{/if}
|
{/if}
|
||||||
{sectionelse}
|
{sectionelse}
|
||||||
none
|
none
|
||||||
@@ -27,9 +27,9 @@ My interests are:
|
|||||||
|
|
||||||
testing section looped key values<br>
|
testing section looped key values<br>
|
||||||
{section name=sec1 loop=$contacts}
|
{section name=sec1 loop=$contacts}
|
||||||
phone: {$sec1/contacts.phone}<br>
|
phone: {$contacts[sec1].phone}<br>
|
||||||
fax: {$sec1/contacts.fax}<br>
|
fax: {$contacts[sec1].fax}<br>
|
||||||
cell: {$sec1/contacts.cell}<br>
|
cell: {$contacts[sec1].cell}<br>
|
||||||
{/section}
|
{/section}
|
||||||
<p>
|
<p>
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user