mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-05 02:44:27 +02:00
Added section "Escaping Smarty Parsing" under Basic Syntax.
This commit is contained in:
@@ -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 = '<!--{';
|
||||||
|
$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>
|
||||||
|
|
||||||
|
</programlisting>
|
||||||
|
</example>
|
||||||
|
|
||||||
|
</sect1>
|
||||||
</chapter>
|
</chapter>
|
||||||
|
|
||||||
<chapter id="language.variables">
|
<chapter id="language.variables">
|
||||||
|
Reference in New Issue
Block a user