{$title|default:"no title"}
+{$title}
--------- 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
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
-"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.
IF/ELSEIF/ELSE
@@ -236,7 +236,7 @@ $smarty->display("index.tpl");
--------- templates/index.tpl --------
{include file="header.tpl" title="Home Page"}
{section name=people loop=$FirstName}
- {%people.rownum%} {$people/FirstName} {$people/LastName}
+ {%people.rownum%} {$FirstName[people]} {$LastName[people]}
{sectionelse}
There are no values to loop through.
{/section}
@@ -278,11 +278,11 @@ $smarty->display("index.tpl");
--------- templates/index.tpl --------
{include file="header.tpl" title="Home Page"}
{section name=people loop=$FirstName}
- {%people.rownum%} {$people/FirstName} {$people/LastName}
- {section name=contacts loop=$people/ContactNames}
+ {%people.rownum%} {$FirstName[people]} {$LastName[people]}
+ {section name=contacts loop=$ContactNames[people]}
{* for fun, lets bold every other row *}
{if %contacts.rownum% is even}{/if}
- {$people/contacts/ContactNames}: {$people/contacts/ContactVals}
+ {$ContactNames[people][contacts]}: {$ContactVals[people][contacts]}
{if %contacts.rownum% is even}{/if}
{/section}
diff --git a/RELEASE_NOTES b/RELEASE_NOTES
index 33dfea37..3f799207 100644
--- a/RELEASE_NOTES
+++ b/RELEASE_NOTES
@@ -1,17 +1,29 @@
1.4.0
-----
-The most significant change to Smarty 1.4.0 is the compilation process. Instead
-of compiling all the templates up front, it now compiles them at runtime. This
-has several advantages. First off, 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.
+IMPORTANT NOTICE: Smarty now has a new syntax for accessing elements within
+section loops. The new syntax is easier to use for complex data structures.
+Consequently, this breaks the old syntax. To fix your old templates, we have
+provided a script that will fix the syntax for you. Located in
+misc/fix_vars.php, run this script from the the command line, giving each
+template as an argument. Be sure to use absolute pathnames, or pathnames
+relative to the executing script. Probably the easiest way to do this is to
+copy the fix_vars.php script into your template directory and run 'php -q
+fix_vars.php *.tpl' For each template, this will create a temporary file with
+the fixes, then move the temp file over top the original. Backup your scripts
+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
of file permissions for better security on public servers. Thanks goes to
diff --git a/demo/templates/index.tpl b/demo/templates/index.tpl
index d485ec19..ad66a50c 100644
--- a/demo/templates/index.tpl
+++ b/demo/templates/index.tpl
@@ -12,14 +12,14 @@ Title: {#title#|capitalize}
the value of $SCRIPT_NAME is {$SCRIPT_NAME}
{* A simple variable test. print $Name in uppercase *}
-hello, my name is {$Name|upper}
+hello, my name is {$Name}
My interests are:
{section name=outer loop=$FirstName}
{if %outer.index% is odd by 2}
- {%outer.rownum%} . {$outer/FirstName} {$outer/LastName}
+ {%outer.rownum%} . {$FirstName[outer]} {$LastName[outer]}
{else}
- {%outer.rownum%} * {$outer/FirstName} {$outer/LastName}
+ {%outer.rownum%} * {$FirstName[outer]} {$LastName[outer]}
{/if}
{sectionelse}
none
@@ -27,9 +27,9 @@ My interests are:
testing section looped key values
{section name=sec1 loop=$contacts}
- phone: {$sec1/contacts.phone}
- fax: {$sec1/contacts.fax}
- cell: {$sec1/contacts.cell}
+ phone: {$contacts[sec1].phone}
+ fax: {$contacts[sec1].fax}
+ cell: {$contacts[sec1].cell}
{/section}
diff --git a/docs.sgml b/docs.sgml
index 6ea4fb1f..1eca4d8c 100644
--- a/docs.sgml
+++ b/docs.sgml
@@ -709,7 +709,7 @@ $smarty->unregister_modifier("fetch");
$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
@@ -1689,9 +1689,9 @@ OUTPUT:
section names must be unique from each other. The loop variable
(usually an array of values) determines the number of times the
section will loop. When printing a variable within a section, the
- section name must be prepended to the variable name, separated by a
- slash (/). If you are using an associative array, separate the key
- and value with a period (.). sectionelse is
+ section name must be given next to variable name within brackets
+ []. If you are using an associative array, separate the key and
+ value with a period (.). sectionelse is
executed when there are no values in the loop variable.
@@ -1701,7 +1701,7 @@ OUTPUT:
{* this example will print out all the values of the $custid array *}
{section name=customer loop=$custid}
- id: {$customer/custid}<br>
+ id: {$custid[customer]}<br>
{/section}
OUTPUT:
@@ -1722,9 +1722,9 @@ id: 1002<br>
This example assumes that $custid, $name and $address are all
arrays containing the same number of values *}
{section name=customer loop=$custid}
- id: {$customer/custid}<br>
- name: {$customer/name}<br>
- address: {$customer/address}<br>
+ id: {$custid[customer]}<br>
+ name: {$name[customer]}<br>
+ address: {$address[customer]}<br>
<p>
{/section}
@@ -1754,9 +1754,9 @@ address: 5605 apple st<br>
{* the name of the section can be anything you like,
and it is used to reference the data within the section *}
{section name=mydata loop=$custid}
- id: {$mydata/custid}<br>
- name: {$mydata/name}<br>
- address: {$mydata/address}<br>
+ id: {$custid[mydata]}<br>
+ name: {$name[mydata]}<br>
+ address: {$address[mydata]}<br>
<p>
{/section}
@@ -1769,14 +1769,14 @@ address: 5605 apple st<br>
{* sections can be nested as deep as you like. With nested sections,
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. *}
{section name=customer loop=$custid}
- id: {$customer/custid}<br>
- name: {$customer/name}<br>
- address: {$customer/address}<br>
- {section name=contact loop=$customer/contact_type}
- {$customer/contact/contact_type}: {$customer/contact/contact_info}<br>
+ id: {$custid[customer]}<br>
+ name: {$name[customer]}<br>
+ address: {$address[customer]}<br>
+ {section name=contact loop=$contact_type[customer]}
+ {$contact_type[customer][contact]}: {$contact_info[customer][contact]}<br>
{/section}
<p>
{/section}
@@ -1817,10 +1817,10 @@ e-mail: jane@mydomain.com<br>
{* This is an example of printing an associative array
of data within a section *}
{section name=customer loop=$contacts}
- name: {$customer/contacts.name}<br>
- home: {$customer/contacts.home}<br>
- cell: {$customer/contacts.cell}<br>
- e-mail: {$customer/contacts.email}<p>
+ name: {$contacts[customer].name}<br>
+ home: {$contacts[customer].home}<br>
+ cell: {$contacts[customer].cell}<br>
+ e-mail: {$contacts[customer].email}<p>
{/section}
@@ -1851,7 +1851,7 @@ e-mail: jane@mydomain.com<p>
{* sectionelse will execute if there are no $custid values *}
{section name=customer loop=$custid}
- id: {$customer/custid}<br>
+ id: {$custid[customer]}<br>
{sectionelse}
there are no values in $custid.
{/section}
@@ -1873,7 +1873,7 @@ e-mail: jane@mydomain.com<p>
section property index
{section name=customer loop=$custid}
- {%customer.index%} id: {$customer/custid}<br>
+ {%customer.index%} id: {$custid[customer]}<br>
{/section}
@@ -1896,9 +1896,9 @@ OUTPUT:
section property index_prev
{section name=customer loop=$custid}
- {%customer.index%} id: {$customer/custid}<br>
- {* FYI, $customer.index/custid and $customer/custid are identical in meaning *}
- {if $customer.index_prev/custid ne $customer.index/custid}
+ {%customer.index%} id: {$custid[customer]}<br>
+ {* FYI, $custid[customer.index] and $custid[customer] are identical in meaning *}
+ {if $custid[customer.index_prev] ne $custid[customer.index]}
The customer id changed<br>
{/if}
{/section}
@@ -1926,9 +1926,9 @@ OUTPUT:
section property index_next
{section name=customer loop=$custid}
- {%customer.index%} id: {$customer/custid}<br>
- {* FYI, $customer.index/custid and $customer/custid are identical in meaning *}
- {if $customer.index_next/custid ne $customer.index/custid}
+ {%customer.index%} id: {$custid[customer]}<br>
+ {* FYI, $custid[customer.index] and $custid[customer] are identical in meaning *}
+ {if $custid[customer.index_next] ne $custid[customer.index]}
The customer id will change<br>
{/if}
{/section}
@@ -1961,7 +1961,7 @@ OUTPUT:
{/if}
<tr><td>{%customer.index%} id:
- {$customer/custid}</td></tr>
+ {$custid[customer]}</td></tr>
{if %customer.last%}
</table>
@@ -1995,7 +1995,7 @@ OUTPUT:
{/if}
<tr><td>{%customer.index%} id:
- {$customer/custid}</td></tr>
+ {$custid[customer]}</td></tr>
{if %customer.last%}
</table>
@@ -2024,7 +2024,7 @@ OUTPUT:
section property rownum
{section name=customer loop=$custid}
- {%customer.rownum%} id: {$customer/custid}<br>
+ {%customer.rownum%} id: {$custid[customer]}<br>
{/section}
@@ -2048,7 +2048,7 @@ OUTPUT:
section property index
{section name=customer loop=$custid}
- {%customer.index%} id: {$customer/custid}<br>
+ {%customer.index%} id: {$custid[customer]}<br>
{/section}
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
application, to regulate whether or not this section shows *}
{section name=customer loop=$custid show=$show_customer_info}
- {%customer.rownum%} id: {$customer/custid}<br>
+ {%customer.rownum%} id: {$custid[customer]}<br>
{/section}
{if %customer.show%}
@@ -2921,7 +2921,7 @@ OUTPUT:
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
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.)
@@ -2934,7 +2934,7 @@ OUTPUT:
{$articleTitle}
-{$articleTitle|capitalize}
+{$articleTitle}
OUTPUT:
@@ -2955,7 +2955,7 @@ Police Begin Campaign To Rundown Jaywalkers.
{$articleTitle}
-{$articleTitle|count_characters}
+{$articleTitle}
OUTPUT:
@@ -2976,7 +2976,7 @@ Cold Wave Linked to Temperatures
{$articleTitle}
-{$articleTitle|count_paragraphs}
+{$articleTitle}
OUTPUT:
@@ -2999,7 +2999,7 @@ Man is Fatally Slain. Death Causes Loneliness, Feeling of Isolation.
{$articleTitle}
-{$articleTitle|count_sentences}
+{$articleTitle}
OUTPUT:
@@ -3020,7 +3020,7 @@ Two Soviet Ships Collide - One Dies. Enraged Cow Injures Farmer with Axe.
{$articleTitle}
-{$articleTitle|count_words}
+{$articleTitle}
OUTPUT:
@@ -3070,9 +3070,9 @@ Dealers Will Hear Car Talk at Noon.
date_format
-{$currentDate|date_format}
-{$currentDate|date_format:"%A, %B %e, %Y"}
-{$currentDate|date_format:"%H:%M:%S"}
+{$currentDate}
+{$currentDate}
+{$currentDate}
OUTPUT:
@@ -3211,7 +3211,7 @@ system's manpage for a full list of valid specifiers.
{* this will display "no title" (without the quotes) if $articleTitle is empty *}
-{$articleTitle|default:"no title"}
+{$articleTitle}
OUTPUT:
@@ -3261,9 +3261,9 @@ no title
{$articleTitle}
-{$articleTitle|escape}
-{$articleTitle|escape:"html"}
-{$articleTitle|escape:"url"}
+{$articleTitle}
+{$articleTitle}
+{$articleTitle}
OUTPUT:
@@ -3285,7 +3285,7 @@ Stiff+Opposition+Expected+to+Casketless+Funeral+Plan
{$articleTitle}
-{$articleTitle|lower}
+{$articleTitle}
OUTPUT:
@@ -3339,8 +3339,8 @@ two convicts evade noose, jury hung.
{$articleTitle}
-{$articleTitle|replace:"Garden":"Vineyard"}
-{$articleTitle|replace:" ":" "}
+{$articleTitle}
+{$articleTitle}
OUTPUT:
@@ -3390,8 +3390,8 @@ Child's Stool Great for Use in Garden.
{$articleTitle}
-{$articleTitle|spacify}
-{$articleTitle|spacify:"^^"}
+{$articleTitle}
+{$articleTitle}
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^
{$number}
-{$number|string_format:"%.2f"}
-{$number|string_format:"%d"}
+{$number}
+{$number}
OUTPUT:
@@ -3462,7 +3462,7 @@ OUTPUT:
{$articleTitle}
-{$articleTitle|strip_tags}
+{$articleTitle}
OUTPUT:
@@ -3531,37 +3531,8 @@ Blind Woman Gets New Kidney from Dad she Hasn't Seen in years.
{$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...
-
-
-
-
-
- upper
-
- This is used to uppercase a variable.
-
-
-upper
-
-
{$articleTitle}
-{$articleTitle|upper}
+{$articleTitle}
OUTPUT:
@@ -3584,129 +3555,17 @@ IF STRIKE ISN'T SETTLED QUICKLY IT MAY LAST A WHILE.
{$articleTitle}
-{$articleTitle|upper|spacify}
-{$articleTitle|lower|spacify|truncate}
-{$articleTitle|lower|truncate:30|spacify}
-{$articleTitle|lower|spacify|truncate:30:". . ."}
-
-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. . .
-
-
-
-
-
- Creating your own Variable Modifiers
-
- 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.
-
-
- add your modifier to the Smarty.addons.php file.
- It is recommended that you prepend your function name
- with smarty_mod_
- 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.
- Thats it! you can now use that modifier
- from within Smarty.
-
-
- You can also add modifiers programatically with the register_modifier API.
-
-
-
-
-
- Troubleshooting
-
-
- Smarty/PHP errors
-
- 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:
-
-
-
-Smarty errors
-
-
-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
-
-
-
-
-
- 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.
-
-
-
- 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.
-
-
-
-PHP parsing errors
-
-
-Parse error: parse error in /path/to/smarty/templates_c/index.tpl.php on line 75
-
-
-
-
-
- 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.
-
-
-
-
- Tips & Tricks
-
-
-
- Dates
-
- 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 date_format for full control over date
- formatting, and also makes it easy to compare dates if necessary.
-
-
-using date_format
-
-
-{$startDate|date_format}
+{$articleTitle}
+{$articleTitle}
+{$articleTitle}
+{$articleTitle}
OUTPUT:
Jan 4, 2001
-{$startDate|date_format:"%Y/%m/%d"}
+{$startDate}
OUTPUT:
@@ -3747,6 +3606,7 @@ function makeTimeStamp($year="",$month="",$day="")
+
diff --git a/templates/index.tpl b/templates/index.tpl
index d485ec19..ad66a50c 100644
--- a/templates/index.tpl
+++ b/templates/index.tpl
@@ -12,14 +12,14 @@ Title: {#title#|capitalize}
the value of $SCRIPT_NAME is {$SCRIPT_NAME}
{* A simple variable test. print $Name in uppercase *}
-hello, my name is {$Name|upper}
+hello, my name is {$Name}
My interests are:
{section name=outer loop=$FirstName}
{if %outer.index% is odd by 2}
- {%outer.rownum%} . {$outer/FirstName} {$outer/LastName}
+ {%outer.rownum%} . {$FirstName[outer]} {$LastName[outer]}
{else}
- {%outer.rownum%} * {$outer/FirstName} {$outer/LastName}
+ {%outer.rownum%} * {$FirstName[outer]} {$LastName[outer]}
{/if}
{sectionelse}
none
@@ -27,9 +27,9 @@ My interests are:
testing section looped key values
{section name=sec1 loop=$contacts}
- phone: {$sec1/contacts.phone}
- fax: {$sec1/contacts.fax}
- cell: {$sec1/contacts.cell}
+ phone: {$contacts[sec1].phone}
+ fax: {$contacts[sec1].fax}
+ cell: {$contacts[sec1].cell}
{/section}