cvs: smarty /docs designers.sgml

"boots" <[email protected]>
Newsgroups gmane.comp.php.cvs.smarty
Message-ID <cvsboots1070282071@cvsserver>
boots		Mon Dec  1 07:34:31 2003 EDT

  Modified files:              
    /smarty/docs	designers.sgml 
  Log:
  Added section "Escaping Smarty Parsing" under Basic Syntax.

-- 
Smarty CVS Mailing List (http://cvs.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
boots-20031201073431.txt (text/plain, 20.7 KB)
Index: smarty/docs/designers.sgml
diff -u smarty/docs/designers.sgml:1.86 smarty/docs/designers.sgml:1.87
--- smarty/docs/designers.sgml:1.86	Wed Nov 19 15:26:28 2003
+++ smarty/docs/designers.sgml	Mon Dec  1 07:34:31 2003
@@ -60,7 +60,7 @@
 {include file="header.tpl"}
 
 {if $highlight_name}
-	Welcome, &lt;font color="{#fontColor#}"&gt;{$name}!&lt;/font&gt;	
+	Welcome, &lt;font color="{#fontColor#}"&gt;{$name}!&lt;/font&gt;
 {else}
 	Welcome, {$name}!
 {/if}
@@ -141,13 +141,13 @@
     </para>
     <example>
      <title>math examples</title>
-     <programlisting>	 
+     <programlisting>
 {$foo+1}
 
 {$foo*$bar}
-	 
+
 {* some more complicated examples *}
-	 
+
 {$foo-&gt;bar-$bar[1]*$baz-&gt;foo-&gt;bar()-3*7}
 
 {if ($foo+$bar.test%$baz*134232+10+$b+10)}
@@ -158,6 +158,52 @@
 </example>
 	</sect1>
 
+   <sect1 id="language.escaping">
+    <title>Escaping Smarty Parsing</title>
+    <para>
+	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.
+    </para>
+
+    <para>
+    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.
+    </para>
+
+    <para>Including literal content is possible using <link linkend="language.function.literal">{literal} .. {/literal}</link> blocks.
+    Similar to HTML entity usage, you can use <link linkend="language.function.ldelim">{ldelim}</link> and <link linkend="language.function.ldelim">{rdelim}</link>
+    to display the current deliminters.
+    </para>
+
+    <para>
+    It is often convenient to simply change Smarty's <link linkend="variable.left.delimiter">$left_delimiter</link> and
+    <link linkend="variable.right.delimiter">$right_delimiter</link>.
+    </para>
+    <example>
+     <title>changing delimiters example</title>
+     <programlisting>
+
+$smarty = new Smarty;
+$smarty->left_delimiter = '&lt;!--{';
+$smarty->right_delimiter = '}--&gt;';
+$smarty->assign('foo', 'bar');
+$smarty->display('example.tpl');
+
+--- example.tpl
+&lt;script language="javascript"&gt;
+var foo = &lt;!--{$foo}--&gt;;
+function dosomething() {
+    alert("foo is " + foo);
+}
+dosomething();
+&lt;/script&gt;
+
+</programlisting>
+</example>
+
+	</sect1>
   </chapter>
 
   <chapter id="language.variables">
@@ -166,7 +212,7 @@
 	Smarty has several different types of variables. The type of the variable
 	depends on what symbol it is prefixed with (or enclosed within).
    </para>
-   
+
    <para>
     Variables in Smarty can be either displayed directly or used as arguments
     for function attributes and modifiers, inside conditional expressions,
@@ -686,7 +732,7 @@
 
 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</programlisting>
@@ -755,7 +801,7 @@
                     <row>
                         <entry>Parameter Position</entry>
                         <entry>Type</entry>
-                        <entry>Required</entry>       
+                        <entry>Required</entry>
                         <entry>Default</entry>
                         <entry>Description</entry>
                     </row>
@@ -818,82 +864,82 @@
 <example>
 <title>date_format conversion specifiers</title>
 <programlisting>
-%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 @@
                     <row>
                         <entry>Parameter Position</entry>
                         <entry>Type</entry>
-                        <entry>Required</entry>       
+                        <entry>Required</entry>
                         <entry>Default</entry>
                         <entry>Description</entry>
                     </row>
@@ -1676,7 +1722,7 @@
 $smarty-&gt;display('index.tpl');
 
 index.tpl:
-		 
+
 {$articleTitle}
 {$articleTitle|upper|spacify}
 {$articleTitle|lower|spacify|truncate}
@@ -1715,7 +1761,7 @@
                     <row>
                         <entry>Attribute Name</entry>
                         <entry>Type</entry>
-                        <entry>Required</entry>       
+                        <entry>Required</entry>
                         <entry>Default</entry>
                         <entry>Description</entry>
                     </row>
@@ -1795,7 +1841,7 @@
                     <row>
                         <entry>Attribute Name</entry>
                         <entry>Type</entry>
-                        <entry>Required</entry>       
+                        <entry>Required</entry>
                         <entry>Default</entry>
                         <entry>Description</entry>
                     </row>
@@ -1913,7 +1959,7 @@
                     <row>
                         <entry>Attribute Name</entry>
                         <entry>Type</entry>
-                        <entry>Required</entry>       
+                        <entry>Required</entry>
                         <entry>Default</entry>
                         <entry>Description</entry>
                     </row>
@@ -2049,7 +2095,7 @@
 			</para>
 			</sect2>
 
-			<sect2 id="foreach.property.show">	
+			<sect2 id="foreach.property.show">
 			<title>show</title>
 			<para>
         	<emphasis>show</emphasis> is used as a parameter to foreach.
@@ -2059,7 +2105,7 @@
 			</para>
 
 			</sect2>
-			<sect2 id="foreach.property.total">	
+			<sect2 id="foreach.property.total">
 			<title>total</title>
 			<para>
 			<emphasis>total</emphasis> is used to display the number of iterations that this foreach
@@ -2085,7 +2131,7 @@
                     <row>
                         <entry>Attribute Name</entry>
                         <entry>Type</entry>
-                        <entry>Required</entry>       
+                        <entry>Required</entry>
                         <entry>Default</entry>
                         <entry>Description</entry>
                     </row>
@@ -2187,7 +2233,7 @@
                     <row>
                         <entry>Attribute Name</entry>
                         <entry>Type</entry>
-                        <entry>Required</entry>       
+                        <entry>Required</entry>
                         <entry>Default</entry>
                         <entry>Description</entry>
                     </row>
@@ -2294,7 +2340,7 @@
                     <row>
                         <entry>Attribute Name</entry>
                         <entry>Type</entry>
-                        <entry>Required</entry>       
+                        <entry>Required</entry>
                         <entry>Default</entry>
                         <entry>Description</entry>
                     </row>
@@ -2482,7 +2528,7 @@
 		<sect1 id="language.function.ldelim">
 			<title>ldelim,rdelim</title>
 			<para>
-			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.
 			</para>
@@ -2517,7 +2563,7 @@
 
         	&lt;!--
                 	function isblank(field) {
-                	if (field.value == '') 
+                	if (field.value == '')
                         	{ return false; }
                 	else
                         	{
@@ -2562,7 +2608,7 @@
                     <row>
                         <entry>Attribute Name</entry>
                         <entry>Type</entry>
-                        <entry>Required</entry>       
+                        <entry>Required</entry>
                         <entry>Default</entry>
                         <entry>Description</entry>
                     </row>
@@ -2793,7 +2839,7 @@
 		supported, but you will only see reference to the new syntax in the
 		manual examples.
 		</para>
-			<sect2 id="section.property.index">	
+			<sect2 id="section.property.index">
 			<title>index</title>
 			<para>
 			index is used to display the current loop index, starting with zero
@@ -2824,7 +2870,7 @@
 </programlisting>
 	</example>
 			</sect2>
-			<sect2 id="section.property.index.prev">	
+			<sect2 id="section.property.index.prev">
 			<title>index_prev</title>
 			<para>
 			index_prev is used to display the previous loop index.
@@ -2987,7 +3033,7 @@
 </programlisting>
 	</example>
 			</sect2>
-			<sect2 id="section.property.rownum">	
+			<sect2 id="section.property.rownum">
 			<title>rownum</title>
 			<para>
 			rownum is used to display the current loop iteration,
@@ -3010,7 +3056,7 @@
 </programlisting>
 	</example>
 			</sect2>
-			<sect2 id="section.property.loop">	
+			<sect2 id="section.property.loop">
 			<title>loop</title>
 			<para>
 			loop is used to display the last index number that this section
@@ -3035,7 +3081,7 @@
 </programlisting>
 	</example>
 			</sect2>
-			<sect2 id="section.property.show">	
+			<sect2 id="section.property.show">
 			<title>show</title>
 			<para>
         	<emphasis>show</emphasis> is used as a parameter to section.
@@ -3069,7 +3115,7 @@
 </programlisting>
 	</example>
 			</sect2>
-			<sect2 id="section.property.total">	
+			<sect2 id="section.property.total">
 			<title>total</title>
 			<para>
 			total is used to display the number of iterations that this section
@@ -3078,7 +3124,7 @@
 	<example>
 	<title>section property total</title>
 	<programlisting>
-	{section name=customer loop=$custid step=2}	
+	{section name=customer loop=$custid step=2}
 	{$smarty.section.customer.index} id: {$custid[customer]}&lt;br&gt;
 	{/section}
 
@@ -3168,7 +3214,7 @@
                     <row>
                         <entry>Attribute Name</entry>
                         <entry>Type</entry>
-                        <entry>Required</entry>       
+                        <entry>Required</entry>
                         <entry>Default</entry>
                         <entry>Description</entry>
                     </row>
@@ -3220,7 +3266,7 @@
                     <row>
                         <entry>Attribute Name</entry>
                         <entry>Type</entry>
-                        <entry>Required</entry>       
+                        <entry>Required</entry>
                         <entry>Default</entry>
                         <entry>Description</entry>
                     </row>
@@ -3317,7 +3363,7 @@
                     <row>
                         <entry>Attribute Name</entry>
                         <entry>Type</entry>
-                        <entry>Required</entry>       
+                        <entry>Required</entry>
                         <entry>Default</entry>
                         <entry>Description</entry>
                     </row>
@@ -3431,7 +3477,7 @@
                     <row>
                         <entry>Attribute Name</entry>
                         <entry>Type</entry>
-                        <entry>Required</entry>       
+                        <entry>Required</entry>
                         <entry>Default</entry>
                         <entry>Description</entry>
                     </row>
@@ -3469,7 +3515,7 @@
                     <row>
                         <entry>Attribute Name</entry>
                         <entry>Type</entry>
-                        <entry>Required</entry>       
+                        <entry>Required</entry>
                         <entry>Default</entry>
                         <entry>Description</entry>
                     </row>
@@ -3566,7 +3612,7 @@
                     <row>
                         <entry>Attribute Name</entry>
                         <entry>Type</entry>
-                        <entry>Required</entry>       
+                        <entry>Required</entry>
                         <entry>Default</entry>
                         <entry>Description</entry>
                     </row>
@@ -3651,7 +3697,7 @@
                     <row>
                         <entry>Attribute Name</entry>
                         <entry>Type</entry>
-                        <entry>Required</entry>       
+                        <entry>Required</entry>
                         <entry>Default</entry>
                         <entry>Description</entry>
                     </row>
@@ -3776,7 +3822,7 @@
                     <row>
                         <entry>Attribute Name</entry>
                         <entry>Type</entry>
-                        <entry>Required</entry>       
+                        <entry>Required</entry>
                         <entry>Default</entry>
                         <entry>Description</entry>
                     </row>
@@ -3855,7 +3901,7 @@
 				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.
             	</para>
 			</note>
 <example>
@@ -3897,7 +3943,7 @@
                     <row>
                         <entry>Attribute Name</entry>
                         <entry>Type</entry>
-                        <entry>Required</entry>       
+                        <entry>Required</entry>
                         <entry>Default</entry>
                         <entry>Description</entry>
                     </row>
@@ -4024,7 +4070,7 @@
                     <row>
                         <entry>Attribute Name</entry>
                         <entry>Type</entry>
-                        <entry>Required</entry>       
+                        <entry>Required</entry>
                         <entry>Default</entry>
                         <entry>Description</entry>
                     </row>
@@ -4144,7 +4190,7 @@
                     <row>
                         <entry>Attribute Name</entry>
                         <entry>Type</entry>
-                        <entry>Required</entry>       
+                        <entry>Required</entry>
                         <entry>Default</entry>
                         <entry>Description</entry>
                     </row>
@@ -4438,7 +4484,7 @@
                     <row>
                         <entry>Attribute Name</entry>
                         <entry>Type</entry>
-                        <entry>Required</entry>       
+                        <entry>Required</entry>
                         <entry>Default</entry>
                         <entry>Description</entry>
                     </row>
@@ -4739,7 +4785,7 @@
                     <row>
                         <entry>Attribute Name</entry>
                         <entry>Type</entry>
-                        <entry>Required</entry>       
+                        <entry>Required</entry>
                         <entry>Default</entry>
                         <entry>Description</entry>
                     </row>
@@ -4866,7 +4912,7 @@
                     <row>
                         <entry>Attribute Name</entry>
                         <entry>Type</entry>
-                        <entry>Required</entry>       
+                        <entry>Required</entry>
                         <entry>Default</entry>
                         <entry>Description</entry>
                     </row>
@@ -4990,7 +5036,7 @@
                     <row>
                         <entry>Attribute Name</entry>
                         <entry>Type</entry>
-                        <entry>Required</entry>       
+                        <entry>Required</entry>
                         <entry>Default</entry>
                         <entry>Description</entry>
                     </row>
@@ -5146,7 +5192,7 @@
                     <row>
                         <entry>Attribute Name</entry>
                         <entry>Type</entry>
-                        <entry>Required</entry>       
+                        <entry>Required</entry>
                         <entry>Default</entry>
                         <entry>Description</entry>
                     </row>
@@ -5553,7 +5599,7 @@
                     <row>
                         <entry>Attribute Name</entry>
                         <entry>Type</entry>
-                        <entry>Required</entry>       
+                        <entry>Required</entry>
                         <entry>Default</entry>
                         <entry>Description</entry>
                     </row>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.