Added section "Escaping Smarty Parsing" under Basic Syntax.

This commit is contained in:
boots
2003-12-01 12:34:31 +00:00
parent bb0771505a
commit 8073010cc7

View File

@@ -158,6 +158,52 @@ PRACTICAL EXAMPLES:
</example> </example>
</sect1> </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>
<chapter id="language.variables"> <chapter id="language.variables">