-
Notifications
You must be signed in to change notification settings - Fork 35
escape
Umakant Patil edited this page Aug 14, 2017
·
8 revisions
_escape _is used to encode or escape a variable to html, url, single quotes, hex, hexentity, _javascript _ and mail. By default its html.
This modifier for some formats may use JavaScript ports of PHP functions htmlspecialchars(), htmlentities, rawurlencode You can find them at phpjs.org
Parameter Position | Type | Required | Default | Description |
---|---|---|---|---|
1 | string | No | html | This is the escape format to use. Possible values are: html, htmlall, url, urlpathinfo, quotes, hex, hexentity, decentity, mail, nonstd, javascript |
2 | string | No | UTF-8 | The character set encoding passed to htmlentities() et. al. ISO-8859-1, UTF-8, and any character set supported by htmlentities() |
3 | boolean | No | true | Double encode entites from & to & (applys to html and htmlall only) |
Template:
{$articleTitle = "'Stiff Opposition Expected to Casketless Funeral Plan'"}
{$EmailAddress= "smarty@example.com"}
{$articleTitle}
{$articleTitle|escape}
{$articleTitle|escape:'html'} {* escapes & " ' < > *}
{$articleTitle|escape:'htmlall'} {* escapes ALL html entities *}
<a href="?title={$articleTitle|escape:'url'}">click here</a>
{$articleTitle|escape:'quotes'}
<a href="mailto:{$EmailAddress|escape:"hex"}">{$EmailAddress|escape:"hexentity"}</a>
{$EmailAddress|escape:'mail'} {* this converts to email to text *}
{'mail@example.com'|escape:'mail'}
output:
'Stiff Opposition Expected to Casketless Funeral Plan'
'Stiff Opposition Expected to Casketless Funeral Plan'
'Stiff Opposition Expected to Casketless Funeral Plan'
'Stiff Opposition Expected to Casketless Funeral Plan'
<a
href="?title=%27Stiff%20Opposition%20Expected%20to%20Casketless%20Funeral%20Plan%27">click here</a>
\'Stiff Opposition Expected to Casketless Funeral Plan\'
<a href="mailto:%62%6f%..snip..%65%74">bob..snip..et</a>
smarty [AT] example [DOT] com
mail [AT] example [DOT] com
see also escape in PHP Smarty documentation