<?xml version="1.0" encoding="UTF-8"?>
<!-- $Revision: 4740 $ -->
 <sect1 id="language.modifier.escape">
  <title>escape</title>
    <para>
    <varname>escape</varname> is used to encode or escape a variable to <literal>html</literal>,
     <literal>url</literal>, <literal>single quotes</literal>,
     <literal>hex</literal>, <literal>hexentity</literal>,
     <literal>javascript</literal> and <literal>mail</literal>.
     By default its <literal>html</literal>.
  </para>

  <informaltable frame="all">
   <tgroup cols="6">
    <colspec colname="param" align="center" />
    <colspec colname="type" align="center" />
    <colspec colname="required" align="center" />
    <colspec colname="possible" align="center" />
    <colspec colname="default" align="center" />
    <colspec colname="desc" />
    <thead>
     <row>
      <entry>Parameter Position</entry>
      <entry>Type</entry>
      <entry>Required</entry>
      <entry>Possible Values</entry>
      <entry>Default</entry>
      <entry>Description</entry>
     </row>
    </thead>
    <tbody>
     <row>
      <entry>1</entry>
      <entry>string</entry>
      <entry>No</entry>
      <entry><literal>html</literal>, <literal>htmlall</literal>,
              <literal>url</literal>,
               <literal>urlpathinfo</literal>, <literal>quotes</literal>,
               <literal>hex</literal>, <literal>hexentity</literal>,
               <literal>javascript</literal>, <literal>mail</literal>
       </entry>
      <entry><literal>html</literal></entry>
      <entry>This is the escape format to use.</entry>
     </row>
     <row>
      <entry>2</entry>
      <entry>string</entry>
      <entry>No</entry>
      <entry><literal>ISO-8859-1</literal>, <literal>UTF-8</literal>,
      and any character set supported by
      <ulink url="&url.php-manual;htmlentities">
      <varname>htmlentities()</varname></ulink>
      </entry>
      <entry><literal>UTF-8</literal></entry>
      <entry>The character set encoding passed to htmlentities() et. al.</entry>
     </row>
     <row>
      <entry>3</entry>
      <entry>boolean</entry>
      <entry>No</entry>
      <entry>&false;</entry>
      <entry>&true;</entry>
      <entry>Double encode entites from &amp;amp; to &amp;amp;amp; (applys to <literal>html</literal> and <literal>htmlall</literal> only)</entry>
     </row>
    </tbody>
   </tgroup>
  </informaltable>

  <example>
   <title>escape</title>
   <programlisting role="php">
<![CDATA[
<?php

$smarty->assign('articleTitle',
                "'Stiff Opposition Expected to Casketless Funeral Plan'"
                );
$smarty->assign('EmailAddress','smarty@example.com');

?>
]]>
   </programlisting>
   <para>
   These are example <literal>escape</literal> template lines followed by the output
   </para>
   <programlisting>
<![CDATA[
{$articleTitle}
'Stiff Opposition Expected to Casketless Funeral Plan'

{$articleTitle|escape}
&#039;Stiff Opposition Expected to Casketless Funeral Plan&#039;

{$articleTitle|escape:'html'}    {* escapes  & " ' < > *}
&#039;Stiff Opposition Expected to Casketless Funeral Plan&#039;

{$articleTitle|escape:'htmlall'} {* escapes ALL html entities *}
&#039;Stiff Opposition Expected to Casketless Funeral Plan&#039;

<a href="?title={$articleTitle|escape:'url'}">click here</a>
<a
href="?title=%27Stiff%20Opposition%20Expected%20to%20Casketless%20Funeral%20Plan%27">click here</a>

{$articleTitle|escape:'quotes'}
\'Stiff Opposition Expected to Casketless Funeral Plan\'

<a href="mailto:{$EmailAddress|escape:"hex"}">{$EmailAddress|escape:"hexentity"}</a>
{$EmailAddress|escape:'mail'}    {* this converts to email to text *}
<a href="mailto:%62%6f%..snip..%65%74">&#x62;&#x6f;&#x62..snip..&#x65;&#x74;</a>

{'mail@example.com'|escape:'mail'}
smarty [AT] example [DOT] com
]]>
   </programlisting>
   </example>

   <example>
   <title>Other examples</title>
    <screen>
<![CDATA[
{* the "rewind" parameter registers the current location *}
<a href="$my_path?page=foo&rewind=$my_uri|urlencode}">click here</a>
]]>
   </screen>
      <para>This snippet is useful for emails, but see also
      <link linkend="language.function.mailto">
      <varname>{mailto}</varname></link></para>
      <screen>
<![CDATA[
{* email address mangled *}
<a href="mailto:{$EmailAddress|escape:'hex'}">{$EmailAddress|escape:'mail'}</a>
]]>
   </screen>
  </example>

  <para>
   See also
   <link linkend="language.escaping">escaping smarty parsing</link>,
   <link linkend="language.function.mailto"><varname>{mailto}</varname></link>
   and the
   <link linkend="tips.obfuscating.email">obfuscating email addresses</link> page.
  </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
-->
