mirror of
https://github.com/smarty-php/smarty.git
synced 2025-11-09 08:41:39 +01:00
89 lines
2.4 KiB
XML
89 lines
2.4 KiB
XML
<?xml version="1.0" encoding="UTF-8"?>
|
|
<!-- $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">
|
|
<varname>{literal}..{/literal}</varname></link> blocks.
|
|
Similar to HTML entity usage, you can use <link
|
|
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.
|
|
</para>
|
|
|
|
<para>
|
|
It is often convenient to simply change Smarty's <link
|
|
linkend="variable.left.delimiter">
|
|
<parameter>$left_delimiter</parameter></link> and
|
|
<link linkend="variable.right.delimiter">
|
|
<parameter>$right_delimiter</parameter></link>.
|
|
</para>
|
|
<example>
|
|
<title>changing delimiters example</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
|
|
$smarty->left_delimiter = '<!--{';
|
|
$smarty->right_delimiter = '}-->';
|
|
|
|
$smarty->assign('foo', 'bar');
|
|
$smarty->assign('name', 'Albert');
|
|
$smarty->display('example.tpl');
|
|
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
<para>
|
|
Where the template is:
|
|
</para>
|
|
<programlisting>
|
|
<![CDATA[
|
|
Welcome <!--{$name}--> to Smarty
|
|
<script language="javascript">
|
|
var foo = <!--{$foo}-->;
|
|
function dosomething() {
|
|
alert("foo is " + foo);
|
|
}
|
|
dosomething();
|
|
</script>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</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
|
|
-->
|