diff --git a/docs/designers.sgml b/docs/designers.sgml index 0a96a145..90ae7a90 100644 --- a/docs/designers.sgml +++ b/docs/designers.sgml @@ -60,7 +60,7 @@ {include file="header.tpl"} {if $highlight_name} - Welcome, <font color="{#fontColor#}">{$name}!</font> + Welcome, <font color="{#fontColor#}">{$name}!</font> {else} Welcome, {$name}! {/if} @@ -141,13 +141,13 @@ PRACTICAL EXAMPLES: math examples - + {$foo+1} {$foo*$bar} - + {* some more complicated examples *} - + {$foo->bar-$bar[1]*$baz->foo->bar()-3*7} {if ($foo+$bar.test%$baz*134232+10+$b+10)} @@ -158,6 +158,52 @@ PRACTICAL EXAMPLES: + + Escaping Smarty Parsing + + It is sometimes desirable or even necessary to have Smarty ignore sections it + would otherwise parse. A classic example is embedding Javascript or CSS code in + a template. The problem arises as those languages use the { and } characters + which are also the default delimiters for Smarty. + + + + The simplest thing is to avoid the situation altogether by separating your Javascript + and CSS code into their own files and then using standard HTML methods to access them. + + + Including literal content is possible using {literal} .. {/literal} blocks. + Similar to HTML entity usage, you can use {ldelim} and {rdelim} + to display the current deliminters. + + + + It is often convenient to simply change Smarty's $left_delimiter and + $right_delimiter. + + + changing delimiters example + + +$smarty = new Smarty; +$smarty->left_delimiter = '<!--{'; +$smarty->right_delimiter = '}-->'; +$smarty->assign('foo', 'bar'); +$smarty->display('example.tpl'); + +--- example.tpl +<script language="javascript"> +var foo = <!--{$foo}-->; +function dosomething() { + alert("foo is " + foo); +} +dosomething(); +</script> + + + + + @@ -166,7 +212,7 @@ PRACTICAL EXAMPLES: Smarty has several different types of variables. The type of the variable depends on what symbol it is prefixed with (or enclosed within). - + Variables in Smarty can be either displayed directly or used as arguments for function attributes and modifiers, inside conditional expressions, @@ -686,7 +732,7 @@ index.tpl: OUTPUT: -War Dims Hope for Peace. Child's Death Ruins Couple's Holiday. +War Dims Hope for Peace. Child's Death Ruins Couple's Holiday. Man is Fatally Slain. Death Causes Loneliness, Feeling of Isolation. 2 @@ -755,7 +801,7 @@ Dealers Will Hear Car Talk at Noon. Parameter Position Type - Required + Required Default Description @@ -818,82 +864,82 @@ Monday, February 5, 2001 date_format conversion specifiers -%a - abbreviated weekday name according to the current locale +%a - abbreviated weekday name according to the current locale -%A - full weekday name according to the current locale +%A - full weekday name according to the current locale -%b - abbreviated month name according to the current locale +%b - abbreviated month name according to the current locale -%B - full month name according to the current locale +%B - full month name according to the current locale -%c - preferred date and time representation for the current locale +%c - preferred date and time representation for the current locale -%C - century number (the year divided by 100 and truncated to an integer, range 00 to 99) +%C - century number (the year divided by 100 and truncated to an integer, range 00 to 99) -%d - day of the month as a decimal number (range 00 to 31) +%d - day of the month as a decimal number (range 00 to 31) -%D - same as %m/%d/%y +%D - same as %m/%d/%y %e - day of the month as a decimal number, a single digit is preceded by a -space (range 1 to 31) +space (range 1 to 31) %g - Week-based year within century [00,99] %G - Week-based year, including the century [0000,9999] -%h - same as %b +%h - same as %b -%H - hour as a decimal number using a 24-hour clock (range 00 to 23) +%H - hour as a decimal number using a 24-hour clock (range 00 to 23) -%I - hour as a decimal number using a 12-hour clock (range 01 to 12) +%I - hour as a decimal number using a 12-hour clock (range 01 to 12) -%j - day of the year as a decimal number (range 001 to 366) +%j - day of the year as a decimal number (range 001 to 366) %k - Hour (24-hour clock) single digits are preceded by a blank. (range 0 to 23) %l - hour as a decimal number using a 12-hour clock, single digits preceeded by a space (range 1 to 12) -%m - month as a decimal number (range 01 to 12) +%m - month as a decimal number (range 01 to 12) -%M - minute as a decimal number +%M - minute as a decimal number -%n - newline character +%n - newline character -%p - either `am' or `pm' according to the given time value, or the corresponding strings for the current locale +%p - either `am' or `pm' according to the given time value, or the corresponding strings for the current locale -%r - time in a.m. and p.m. notation +%r - time in a.m. and p.m. notation -%R - time in 24 hour notation +%R - time in 24 hour notation -%S - second as a decimal number +%S - second as a decimal number -%t - tab character +%t - tab character -%T - current time, equal to %H:%M:%S +%T - current time, equal to %H:%M:%S -%u - weekday as a decimal number [1,7], with 1 representing Monday +%u - weekday as a decimal number [1,7], with 1 representing Monday -%U - week number of the current year as a decimal number, starting with the first Sunday as the first day of the first week +%U - week number of the current year as a decimal number, starting with the first Sunday as the first day of the first week %V - The ISO 8601:1988 week number of the current year as a decimal number, range 01 to 53, where week 1 -is the first week that has at least 4 days in the current year, and with Monday as the first day of the week. +is the first week that has at least 4 days in the current year, and with Monday as the first day of the week. -%w - day of the week as a decimal, Sunday being 0 +%w - day of the week as a decimal, Sunday being 0 -%W - week number of the current year as a decimal number, starting with the first Monday as the first day of the first week +%W - week number of the current year as a decimal number, starting with the first Monday as the first day of the first week -%x - preferred date representation for the current locale without the time +%x - preferred date representation for the current locale without the time -%X - preferred time representation for the current locale without the date +%X - preferred time representation for the current locale without the date -%y - year as a decimal number without a century (range 00 to 99) +%y - year as a decimal number without a century (range 00 to 99) -%Y - year as a decimal number including the century +%Y - year as a decimal number including the century -%Z - time zone or name or abbreviation +%Z - time zone or name or abbreviation -%% - a literal `%' character +%% - a literal `%' character PROGRAMMERS NOTE: date_format is essentially a wrapper to PHP's strftime() @@ -916,7 +962,7 @@ system's manpage for a full list of valid specifiers. Parameter Position Type - Required + Required Default Description @@ -1676,7 +1722,7 @@ $smarty->assign('articleTitle', 'Smokers are Productive, but Death Cuts Effic $smarty->display('index.tpl'); index.tpl: - + {$articleTitle} {$articleTitle|upper|spacify} {$articleTitle|lower|spacify|truncate} @@ -1715,7 +1761,7 @@ s m o k e r s a r e p. . . Attribute Name Type - Required + Required Default Description @@ -1795,7 +1841,7 @@ s m o k e r s a r e p. . . Attribute Name Type - Required + Required Default Description @@ -1913,7 +1959,7 @@ s m o k e r s a r e p. . . Attribute Name Type - Required + Required Default Description @@ -2049,7 +2095,7 @@ cell: 760-1234<br> - + show show is used as a parameter to foreach. @@ -2059,7 +2105,7 @@ cell: 760-1234<br> - + total total is used to display the number of iterations that this foreach @@ -2085,7 +2131,7 @@ cell: 760-1234<br> Attribute Name Type - Required + Required Default Description @@ -2187,7 +2233,7 @@ cell: 760-1234<br> Attribute Name Type - Required + Required Default Description @@ -2294,7 +2340,7 @@ index.tpl Attribute Name Type - Required + Required Default Description @@ -2482,7 +2528,7 @@ index.tpl ldelim,rdelim - ldelim and rdelim are used for displaying the literal delimiter, in + ldelim and rdelim are used for displaying the literal delimiter, in our case "{" or "}". The template engine always tries to interpret delimiters, so this is the way around that. @@ -2517,7 +2563,7 @@ OUTPUT: <!-- function isblank(field) { - if (field.value == '') + if (field.value == '') { return false; } else { @@ -2562,7 +2608,7 @@ OUTPUT: Attribute Name Type - Required + Required Default Description @@ -2793,7 +2839,7 @@ e-mail: jane@mydomain.com<p> supported, but you will only see reference to the new syntax in the manual examples. - + index index is used to display the current loop index, starting with zero @@ -2824,7 +2870,7 @@ e-mail: jane@mydomain.com<p> - + index_prev index_prev is used to display the previous loop index. @@ -2987,7 +3033,7 @@ e-mail: jane@mydomain.com<p> - + rownum rownum is used to display the current loop iteration, @@ -3010,7 +3056,7 @@ e-mail: jane@mydomain.com<p> - + loop loop is used to display the last index number that this section @@ -3035,7 +3081,7 @@ e-mail: jane@mydomain.com<p> - + show show is used as a parameter to section. @@ -3069,7 +3115,7 @@ e-mail: jane@mydomain.com<p> - + total total is used to display the number of iterations that this section @@ -3078,7 +3124,7 @@ e-mail: jane@mydomain.com<p> section property total - {section name=customer loop=$custid step=2} + {section name=customer loop=$custid step=2} {$smarty.section.customer.index} id: {$custid[customer]}<br> {/section} @@ -3168,7 +3214,7 @@ OUTPUT: Attribute Name Type - Required + Required Default Description @@ -3220,7 +3266,7 @@ The value of $name is Bob. Attribute Name Type - Required + Required Default Description @@ -3317,7 +3363,7 @@ OUTPUT: Attribute Name Type - Required + Required Default Description @@ -3431,7 +3477,7 @@ OUTPUT: Attribute Name Type - Required + Required Default Description @@ -3469,7 +3515,7 @@ OUTPUT: Attribute Name Type - Required + Required Default Description @@ -3566,7 +3612,7 @@ You must supply a <b>state</b>. Attribute Name Type - Required + Required Default Description @@ -3651,7 +3697,7 @@ You must supply a <b>state</b>. Attribute Name Type - Required + Required Default Description @@ -3776,7 +3822,7 @@ OUTPUT: (both examples) Attribute Name Type - Required + Required Default Description @@ -3855,7 +3901,7 @@ OUTPUT: (both examples) html_image requires a hit to the disk to read the image and calculate the height and width. If you don't use template caching, it is generally better to avoid html_image and leave - image tags static for optimal performance. + image tags static for optimal performance. @@ -3897,7 +3943,7 @@ OUTPUT: (possible) Attribute Name Type - Required + Required Default Description @@ -4024,7 +4070,7 @@ OUTPUT: (both examples) Attribute Name Type - Required + Required Default Description @@ -4144,7 +4190,7 @@ OUTPUT: (both examples) Attribute Name Type - Required + Required Default Description @@ -4438,7 +4484,7 @@ OUTPUT: (current year is 2000) Attribute Name Type - Required + Required Default Description @@ -4739,7 +4785,7 @@ OUTPUT: Attribute Name Type - Required + Required Default Description @@ -4866,7 +4912,7 @@ OUTPUT: Attribute Name Type - Required + Required Default Description @@ -4990,7 +5036,7 @@ OUTPUT: Attribute Name Type - Required + Required Default Description @@ -5146,7 +5192,7 @@ OUTPUT: Attribute Name Type - Required + Required Default Description @@ -5553,7 +5599,7 @@ text="<UL><LI>links<LI>pages<LI>images</UL>" snapx Attribute Name Type - Required + Required Default Description