Files
smarty/docs/en/designers/language-basic-syntax/language-escaping.xml

81 lines
2.1 KiB
XML
Raw Normal View History

2004-04-13 08:46:28 +00:00
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision$ -->
2004-04-18 17:34:12 +00:00
<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>
2004-04-13 08:46:28 +00:00
2004-04-18 17:34:12 +00:00
<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>
2004-04-13 08:46:28 +00:00
2004-04-18 17:34:12 +00:00
<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 delimiters.
</para>
2004-04-13 08:46:28 +00:00
2004-04-18 17:34:12 +00:00
<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">
2004-04-13 08:46:28 +00:00
<![CDATA[
<?php
$smarty = new Smarty;
$smarty->left_delimiter = '<!--{';
$smarty->right_delimiter = '}-->';
$smarty->assign('foo', 'bar');
$smarty->display('example.tpl');
?>
2004-04-18 17:34:12 +00:00
]]>
</programlisting>
<para>
Where example.tpl is:
</para>
<programlisting>
<![CDATA[
2004-04-13 08:46:28 +00:00
<script language="javascript">
var foo = <!--{$foo}-->;
function dosomething() {
alert("foo is " + foo);
}
dosomething();
</script>
]]>
2004-04-18 17:34:12 +00:00
</programlisting>
</example>
2004-04-13 08:46:28 +00:00
</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
2004-04-18 17:34:12 +00:00
-->