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

89 lines
2.4 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
2005-05-27 16:25:02 +00:00
which are also the default
<link linkend="language.function.ldelim">delimiters</link> for Smarty.
2004-04-18 17:34:12 +00:00
</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>
2005-05-27 16:25:02 +00:00
Including literal content is possible using <link
2006-09-26 02:42:08 +00:00
linkend="language.function.literal">
<varname>{literal}..{/literal}</varname></link> blocks.
2005-05-27 16:25:02 +00:00
Similar to HTML entity usage, you can use <link
2006-09-26 02:42:08 +00:00
linkend="language.function.ldelim"><varname>{ldelim}</varname></link>,<link
linkend="language.function.ldelim"><varname>{rdelim}</varname></link> or <link
linkend="language.variables.smarty.ldelim">
<varname>{$smarty.ldelim}</varname></link> to display the current delimiters.
2004-04-18 17:34:12 +00:00
</para>
2004-04-13 08:46:28 +00:00
2004-04-18 17:34:12 +00:00
<para>
2005-05-27 16:25:02 +00:00
It is often convenient to simply change Smarty's <link
2006-09-26 02:42:08 +00:00
linkend="variable.left.delimiter">
<parameter>$left_delimiter</parameter></link> and
<link linkend="variable.right.delimiter">
<parameter>$right_delimiter</parameter></link>.
2004-04-18 17:34:12 +00:00
</para>
<example>
<title>changing delimiters example</title>
<programlisting role="php">
2004-04-13 08:46:28 +00:00
<![CDATA[
<?php
$smarty->left_delimiter = '<!--{';
$smarty->right_delimiter = '}-->';
2006-09-26 02:42:08 +00:00
2004-04-13 08:46:28 +00:00
$smarty->assign('foo', 'bar');
2006-02-18 13:43:35 +00:00
$smarty->assign('name', 'Albert');
2004-04-13 08:46:28 +00:00
$smarty->display('example.tpl');
?>
2004-04-18 17:34:12 +00:00
]]>
</programlisting>
<para>
2006-09-26 02:42:08 +00:00
Where the template is:
2004-04-18 17:34:12 +00:00
</para>
<programlisting>
<![CDATA[
2006-02-18 13:43:35 +00:00
Welcome <!--{$name}--> to Smarty
2004-04-13 08:46:28 +00:00
<script language="javascript">
2005-06-16 17:14:40 +00:00
var foo = <!--{$foo}-->;
2005-05-27 16:25:02 +00:00
function dosomething() {
2004-04-13 08:46:28 +00:00
alert("foo is " + foo);
2005-06-16 17:14:40 +00:00
}
dosomething();
2004-04-13 08:46:28 +00:00
</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
-->