diff --git a/docs/designers.sgml b/docs/designers.sgml
index c6cbcb06..a8b5d80e 100644
--- a/docs/designers.sgml
+++ b/docs/designers.sgml
@@ -22,7 +22,7 @@
Template comments are surrounded by asterisks, and that is surrounded
by the delimiter tags like so: {* this is a comment *}
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.
Comments
@@ -116,13 +116,12 @@
Variables
- Smarty has several different types of variables, all of which are
- explained in more detail below. The type of the variable depends on what
- symbol it is prefixed with (or enclosed within).
+ Smarty has several different types of variables. The type of the variable
+ depends on what symbol it is prefixed with (or enclosed within).
- 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,
etc. To print a variable, simply enclose it in the delimiters so that it
is the only thing contained between them. Examples:
@@ -137,8 +136,10 @@
Variables assigned from PHP
- Variables that are assigned from PHP are referenced by preceding
- them with a dollar sign $.
+ Variables that are assigned from PHP are referenced by preceding them with
+ a dollar sign $. Variables assigned from within the
+ template with the assign
+ function are also displayed this way.
@@ -165,6 +166,18 @@ Your last login was on January 11th, 2001.
accessing associative array variables
+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.email}<br>
{* you can print arrays of arrays as well *}
@@ -176,8 +189,7 @@ OUTPUT:
555-222-9876<br>
zaphod@slartibartfast.com<br>
555-444-3333<br>
-555-111-1234<br>
-
+555-111-1234<br>
@@ -189,11 +201,30 @@ zaphod@slartibartfast.com<br>
accessing arrays by index
+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[1]}<br>
{* you can print arrays of arrays as well *}
-{$Contacts[0][0]}<br>
-{$Contacts[0][1]}<br>
+{$Contacts[2][0]}<br>
+{$Contacts[2][1]}<br>
+
+OUTPUT:
+
+555-222-9876<br>
+zaphod@slartibartfast.com<br>
+555-444-3333<br>
+555-111-1234<br>
@@ -226,6 +257,17 @@ email: zaphod@slartibartfast.com<br>
config variables
+foo.conf:
+
+pageTitle = "This is mine"
+bodyBgColor = "#eeeeee"
+tableBorderSize = "3"
+tableBgColor = "#bbbbbb"
+rowBgColor = "#cccccc"
+
+index.tpl:
+
+{config_load file="foo.conf"}
<html>
<title>{#pageTitle#}</title>
<body bgcolor="{#bodyBgColor#}">
@@ -237,6 +279,21 @@ email: zaphod@slartibartfast.com<br>
</tr>
</table>
</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>
@@ -265,10 +322,10 @@ email: zaphod@slartibartfast.com<br>
displaying request variables
-{* 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}
-{* display the variable "page" from a form using the POST method *}
+{* display the variable "page" from a form a form (POST) *}
{$smarty.post.page}
{* display the value of the cookie "username" *}
@@ -370,6 +427,14 @@ Topic: {$topic|truncate:40:"..."}capitalize
+index.php:
+
+$smarty = new Smarty;
+$smarty->assign('articleTitle', 'Police begin campaign to rundown jaywalkers.');
+$smarty->display('index.tpl');
+
+index.tpl:
+
{$articleTitle}
{$articleTitle|capitalize}
@@ -387,13 +452,20 @@ Police Begin Campaign To Rundown Jaywalkers.count_characters
+index.php:
+
+$smarty = new Smarty;
+$smarty->assign('articleTitle', 'Cold Wave Linked to Temperatures.');
+$smarty->display('index.tpl');
+
+index.tpl:
{$articleTitle}
{$articleTitle|count_characters}
OUTPUT:
-Cold Wave Linked to Temperatures
+Cold Wave Linked to Temperatures.
32
@@ -405,6 +477,13 @@ Cold Wave Linked to Temperatures
count_paragraphs
+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|count_paragraphs}
@@ -425,6 +504,13 @@ Man is Fatally Slain. Death Causes Loneliness, Feeling of Isolation.
count_sentences
+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|count_sentences}
@@ -443,6 +529,13 @@ Two Soviet Ships Collide - One Dies. Enraged Cow Injures Farmer with Axe.
count_words
+index.php:
+
+$smarty = new Smarty;
+$smarty->assign('articleTitle', 'Dealers Will Hear Car Talk at Noon.');
+$smarty->display('index.tpl');
+
+index.tpl:
{$articleTitle}
{$articleTitle|count_words}
@@ -501,14 +594,29 @@ Dealers Will Hear Car Talk at Noon.
date_format
+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:"%A, %B %e, %Y"}
{$smarty.now|date_format:"%H:%M:%S"}
+{$yesterday|date_format}
+{$yesterday|date_format:"%A, %B %e, %Y"}
+{$yesterday|date_format:"%H:%M:%S"}
OUTPUT:
Feb 6, 2001
Tuesday, February 6, 2001
+14:33:00
+Feb 5, 2001
+Monday, February 5, 2001
14:33:00
@@ -637,11 +745,20 @@ system's manpage for a full list of valid specifiers.default
-{* 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"}
+{$myTitle|default:"no title"}
OUTPUT:
+Dealers Will Hear Car Talk at Noon.
no title
@@ -688,6 +805,14 @@ no titleescape
+index.php:
+
+$smarty = new Smarty;
+$smarty->assign('articleTitle', "'Stiff Opposition Expected to Casketless Funeral Plan'");
+$smarty->display('index.tpl');
+
+index.tpl:
+
{$articleTitle}
{$articleTitle|escape}
{$articleTitle|escape:"html"} {* escapes & " ' < > *}
@@ -755,6 +880,14 @@ href="mailto:%62%6f%62%40%6d%65%2e%6e%65%74">bob&a
indent
+index.php:
+
+$smarty = new Smarty;
+$smarty->assign('articleTitle', 'NJ judge to rule on nude beach.');
+$smarty->display('index.tpl');
+
+index.tpl:
+
{$articleTitle}
{$articleTitle|indent}
@@ -790,6 +923,14 @@ Statistics show that teen pregnancy drops off significantly after 25.
lower
+index.php:
+
+$smarty = new Smarty;
+$smarty->assign('articleTitle', 'Two Convicts Evade Noose, Jury Hung.');
+$smarty->display('index.tpl');
+
+index.tpl:
+
{$articleTitle}
{$articleTitle|lower}
@@ -842,6 +983,14 @@ two convicts evade noose, jury hung.regex_replace
+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 *}
{$articleTitle}
@@ -850,8 +999,8 @@ two convicts evade noose, jury hung.
OUTPUT:
Infertility unlikely to
- be passed on, experts say
-Infertility unlikely to be passed on, experts say
+ be passed on, experts say.
+Infertility unlikely to be passed on, experts say.
@@ -896,6 +1045,14 @@ Infertility unlikely to be passed on, experts sayreplace
+index.php:
+
+$smarty = new Smarty;
+$smarty->assign('articleTitle', "Child's Stool Great for Use in Garden.");
+$smarty->display('index.tpl');
+
+index.tpl:
+
{$articleTitle}
{$articleTitle|replace:"Garden":"Vineyard"}
{$articleTitle|replace:" ":" "}
@@ -944,6 +1101,14 @@ Child's Stool Great for Use in Garden.spacify
+index.php:
+
+$smarty = new Smarty;
+$smarty->assign('articleTitle', 'Something Went Wrong in Jet Crash, Experts Say.');
+$smarty->display('index.tpl');
+
+index.tpl:
+
{$articleTitle}
{$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^
string_format
+index.php:
+
+$smarty = new Smarty;
+$smarty->assign('number', 23.5787446);
+$smarty->display('index.tpl');
+
+index.tpl:
+
{$number}
{$number|string_format:"%.2f"}
{$number|string_format:"%d"}
@@ -1018,6 +1191,14 @@ OUTPUT:
strip
+index.php:
+
+$smarty = new Smarty;
+$smarty->assign('articleTitle', "Grandmother of\neight makes\t hole in one.");
+$smarty->display('index.tpl');
+
+index.tpl:
+
{$articleTitle}
{$articleTitle|strip}
{$articleTitle|strip:" "}
@@ -1025,9 +1206,9 @@ OUTPUT:
OUTPUT:
Grandmother of
-eight makes hole in one
-Grandmother of eight makes hole in one
-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.
@@ -1038,6 +1219,14 @@ Grandmother of eight makes hole in&
strip_tags
+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|strip_tags}
@@ -1104,6 +1293,14 @@ Blind Woman Gets New Kidney from Dad she Hasn't Seen in years.truncate
+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|truncate}
{$articleTitle|truncate:30}
@@ -1131,6 +1328,14 @@ Two Sisters Reunite after E...upper
+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|upper}
@@ -1196,6 +1401,14 @@ IF STRIKE ISN'T SETTLED QUICKLY IT MAY LAST A WHILE.wordwrap
+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|wordwrap:30}
@@ -1241,6 +1454,14 @@ s.combining modifiers
+index.php:
+
+$smarty = new Smarty;
+$smarty->assign('articleTitle', 'Smokers are Productive, but Death Cuts Efficiency.');
+$smarty->display('index.tpl');
+
+index.tpl:
+
{$articleTitle}
{$articleTitle|upper|spacify}
{$articleTitle|lower|spacify|truncate}
diff --git a/docs/programmers.sgml b/docs/programmers.sgml
index 55f3aaad..7d2cfc49 100644
--- a/docs/programmers.sgml
+++ b/docs/programmers.sgml
@@ -180,22 +180,20 @@ $smarty->autoload_filters = array('pre' => array('trim', 'stamp'),
$compile_check
- Upon each invocation of the PHP application, Smarty tests to
- see if the current template has changed (later time stamp)
- since the last time it was compiled. If it has changed, it
- recompiles that template. As of 1.4.0, if the template has not
- been compiled, it will compile regardless of this setting. By
- default this variable is set to true. Once an application is
- put into production (templates won't be changing), the
- compile_check step is no longer needed. Be sure to set
- $compile_check to "false" to improve performance! Note that if
- you change this to "false" and a template file is changed, you
- will *not* see the change since the template will not get
- recompiled. If caching is enabled and compile_check is enabled,
- then the cache files will get regenerated if an involved
- template file was updated. See $force_compile or clear_compiled_tpl.
+ Upon each invocation of the PHP application, Smarty tests to see if the
+ current template has changed (different time stamp) since the last time
+ it was compiled. If it has changed, it recompiles that template. If the
+ template has not been compiled, it will compile regardless of this
+ setting. By default this variable is set to true. Once an application is
+ put into production (templates won't be changing), the compile_check
+ step is no longer needed. Be sure to set $compile_check to "false" for
+ maximal performance. Note that if you change this to "false" and a
+ template file is changed, you will *not* see the change since the
+ template will not get recompiled. If caching is enabled and
+ compile_check is enabled, then the cache files will get regenerated if
+ an involved template file or config file was updated. See $force_compile or clear_compiled_tpl.
@@ -302,6 +300,41 @@ $smarty->autoload_filters = array('pre' => array('trim', 'stamp'),
cached content without insert tags.
+
+ $config_overwrite
+
+ 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.
+
+
+
+ $config_booleanize
+
+ 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.
+
+
+
+ $config_read_hidden
+
+ 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.
+
+
+
+ $config_fix_newlines
+
+ 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.
+
+ $default_template_handler_func
@@ -701,6 +734,64 @@ $smarty->clear_compiled_tpl("index.tpl");
// clear entire compile directory
$smarty->clear_compiled_tpl();
+
+
+
+ clear_config
+
+
+ void clear_config
+ string var
+
+
+
+ This clears all assigned config variables. If a variable name is
+ supplied, only that variable is cleared.
+
+
+clear_config
+
+// clear all assigned config variables.
+$smarty->clear_config();
+
+// clear one variable
+$smarty->clear_config('foobar');
+
+
+
+ config_load
+
+
+ void config_load
+ string file
+ string section
+
+
+
+ This loads config file data and assigns it to the template. This
+ works identical to the template config_load
+ function.
+
+
+ Technical Note
+
+ 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 force_compile and compile_check settings.
+
+
+
+config_load
+
+// load config variables and assign them
+$smarty->config_load('my.conf');
+
+// load a section
+$smarty->config_load('my.conf','foobar');