Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 148 | Details | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
991 lars 1
# escape
148 lars 2
 
3
`escape` is used to encode or escape a variable to `html`, `url`,
4
`single quotes`, `hex`, `hexentity`, `javascript` and `mail`. By default
5
its `html`.
6
 
991 lars 7
## Basic usage
8
```smarty
9
{$myVar|escape}
10
```
148 lars 11
 
991 lars 12
## Parameters
148 lars 13
 
991 lars 14
| Parameter Position | Type    | Required | Possible Values                                                                                                | Default | Description                                                                          |
15
|--------------------|---------|----------|----------------------------------------------------------------------------------------------------------------|---------|--------------------------------------------------------------------------------------|
16
| 1                  | string  | No       | `html`, `htmlall`, `url`, `urlpathinfo`, `quotes`, `hex`, `hexentity`, `javascript`, `mail`                    | `html`  | This is the escape format to use.                                                    |
17
| 2                  | string  | No       | `ISO-8859-1`, `UTF-8`, and any character set supported by [`htmlentities()`](https://www.php.net/htmlentities) | `UTF-8` | The character set encoding passed to htmlentities() et. al.                          |
18
| 3                  | boolean | No       | FALSE                                                                                                          | TRUE    | Double encode entities from & to & (applies to `html` and `htmlall` only) |
148 lars 19
 
20
 
991 lars 21
## Examples
148 lars 22
 
991 lars 23
```php
24
<?php
25
 
26
$smarty->assign('articleTitle',
27
                "'Stiff Opposition Expected to Casketless Funeral Plan'"
28
                );
29
$smarty->assign('EmailAddress','smarty@example.com');
30
 
31
```
148 lars 32
 
33
 
34
These are example `escape` template lines followed by the output
35
 
991 lars 36
```smarty
37
{$articleTitle}
38
'Stiff Opposition Expected to Casketless Funeral Plan'
148 lars 39
 
991 lars 40
{$articleTitle|escape}
41
&#039;Stiff Opposition Expected to Casketless Funeral Plan&#039;
148 lars 42
 
991 lars 43
{$articleTitle|escape:'html'}    {* escapes  & " ' < > *}
44
&#039;Stiff Opposition Expected to Casketless Funeral Plan&#039;
148 lars 45
 
991 lars 46
{$articleTitle|escape:'htmlall'} {* escapes ALL html entities *}
47
&#039;Stiff Opposition Expected to Casketless Funeral Plan&#039;
148 lars 48
 
991 lars 49
<a href="?title={$articleTitle|escape:'url'}">click here</a>
50
<a
51
href="?title=%27Stiff%20Opposition%20Expected%20to%20Casketless%20Funeral%20Plan%27">click here</a>
148 lars 52
 
991 lars 53
{$articleTitle|escape:'quotes'}
54
\'Stiff Opposition Expected to Casketless Funeral Plan\'
148 lars 55
 
991 lars 56
<a href="mailto:{$EmailAddress|escape:"hex"}">{$EmailAddress|escape:"hexentity"}</a>
57
{$EmailAddress|escape:'mail'}    {* this converts to email to text *}
58
<a href="mailto:%62%6f%..snip..%65%74">&#x62;&#x6f;&#x62..snip..&#x65;&#x74;</a>
148 lars 59
 
991 lars 60
{'mail@example.com'|escape:'mail'}
61
smarty [AT] example [DOT] com
148 lars 62
 
991 lars 63
{* the "rewind" parameter registers the current location *}
64
<a href="$my_path?page=foo&rewind={$my_uri|escape:url}">click here</a>
148 lars 65
 
991 lars 66
```
148 lars 67
 
68
This snippet is useful for emails, but see also
991 lars 69
[`{mailto}`](../language-custom-functions/language-function-mailto.md)
148 lars 70
 
991 lars 71
```smarty
72
{* email address mangled *}
73
<a href="mailto:{$EmailAddress|escape:'hex'}">{$EmailAddress|escape:'mail'}</a>
74
```
148 lars 75
 
991 lars 76
See also [escaping smarty parsing](../language-basic-syntax/language-escaping.md),
77
[`{mailto}`](../language-custom-functions/language-function-mailto.md) and the [obfuscating email
78
addresses](../../appendixes/tips.md#obfuscating-e-mail-addresses) page.