mirror of
https://github.com/smarty-php/smarty.git
synced 2025-11-01 12:51:38 +01:00
87 lines
2.4 KiB
XML
87 lines
2.4 KiB
XML
<?xml version="1.0" encoding="iso-8859-1"?>
|
|
<!-- $Revision$ -->
|
|
<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
|
|
<link linkend="language.function.ldelim">delimiters</link> 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>,<link
|
|
linkend="language.function.ldelim">{rdelim}</link> or <link
|
|
linkend="language.variables.smarty.ldelim">{$smarty.ldelim}</link>
|
|
to display the current delimiters.
|
|
</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 role="php">
|
|
<![CDATA[
|
|
<?php
|
|
|
|
$smarty = new Smarty;
|
|
$smarty->left_delimiter = '<!--{';
|
|
$smarty->right_delimiter = '}-->';
|
|
$smarty->assign('foo', 'bar');
|
|
$smarty->display('example.tpl');
|
|
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
<para>
|
|
Where example.tpl is:
|
|
</para>
|
|
<programlisting>
|
|
<![CDATA[
|
|
<script language="javascript">
|
|
var foo = <!--{$foo}-->;
|
|
function dosomething() {
|
|
alert("foo is " + foo);
|
|
}
|
|
dosomething();
|
|
</script>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
<para>
|
|
See also <link linkend="language.modifier.escape">escape modifier</link>
|
|
</para>
|
|
</sect1>
|
|
<!-- Keep this comment at the end of the file
|
|
Local variables:
|
|
mode: sgml
|
|
sgml-omittag:t
|
|
sgml-shorttag:t
|
|
sgml-minimize-attributes:nil
|
|
sgml-always-quote-attributes:t
|
|
sgml-indent-step:1
|
|
sgml-indent-data:t
|
|
indent-tabs-mode:nil
|
|
sgml-parent-document:nil
|
|
sgml-default-dtd-file:"../../../../manual.ced"
|
|
sgml-exposed-tags:nil
|
|
sgml-local-catalogs:nil
|
|
sgml-local-ecat-files:nil
|
|
End:
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
vim: et tw=78 syn=sgml
|
|
vi: ts=1 sw=1
|
|
-->
|