Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 148 | Ganze Datei anzeigen | Leerzeichen ignorieren | Details | Blame | Letzte Änderung | Log anzeigen | RSS feed

Revision 148 Revision 991
Zeile 1... Zeile 1...
1
Escaping Smarty Parsing {#language.escaping}
1
# Escaping Smarty parsing
2
=======================
-
 
Zeile 3... Zeile 2...
3
 
2
 
4
It is sometimes desirable or even necessary to have Smarty ignore
3
It is sometimes desirable or even necessary to have Smarty ignore
5
sections it would otherwise parse. A classic example is embedding
4
sections it would otherwise parse. A classic example is embedding
6
Javascript or CSS code in a template. The problem arises as those
5
Javascript or CSS code in a template. The problem arises as those
7
languages use the { and } characters which are also the default
6
languages use the { and } characters which are also the default
Zeile 8... Zeile 7...
8
[delimiters](#language.function.ldelim) for Smarty.
7
[delimiters](../language-builtin-functions/language-function-ldelim.md) for Smarty.
9
 
8
 
10
> **Note**
9
> **Note**
11
>
10
>
Zeile 15... Zeile 14...
15
> caching. When you need to embed Smarty variables/functions into your
14
> caching. When you need to embed Smarty variables/functions into your
16
> Javascript/CSS, then the following applies.
15
> Javascript/CSS, then the following applies.
Zeile 17... Zeile 16...
17
 
16
 
18
In Smarty templates, the { and } braces will be ignored so long as they
17
In Smarty templates, the { and } braces will be ignored so long as they
19
are surrounded by white space. This behavior can be disabled by setting
18
are surrounded by white space. This behavior can be disabled by setting
20
the Smarty class variable [`$auto_literal`](#variable.auto.literal) to
19
the Smarty class variable [`$auto_literal`](../../programmers/api-variables/variable-auto-literal.md) to
Zeile -... Zeile 20...
-
 
20
false.
Zeile -... Zeile 21...
-
 
21
 
21
false.
22
## Examples
22
 
23
 
23
 
24
```smarty
24
    <script>
25
<script>
25
       // the following braces are ignored by Smarty
26
   // the following braces are ignored by Smarty
26
       // since they are surrounded by whitespace
27
   // since they are surrounded by whitespace
27
       function foobar {
28
   function foobar {
28
        alert('foobar!');
29
    alert('foobar!');
29
       }
30
   }
30
       // this one will need literal escapement
31
   // this one will need literal escapement
31
       {literal}
32
   {literal}
32
        function bazzy {alert('foobar!');}
33
    function bazzy {alert('foobar!');}
Zeile 33... Zeile -...
33
       {/literal}
-
 
34
    </script>
34
   {/literal}
35
      
35
</script>
36
     
36
```  
37
 
37
     
38
[`{literal}..{/literal}`](#language.function.literal) blocks are used
-
 
39
for escaping blocks of template logic. You can also escape the braces
38
[`{literal}..{/literal}`](../language-builtin-functions/language-function-literal.md) blocks are used
40
individually with
39
for escaping blocks of template logic. You can also escape the braces
Zeile 41... Zeile 40...
41
[`{ldelim}`](#language.function.ldelim),[`{rdelim}`](#language.function.ldelim)
40
individually with
42
tags or
41
[`{ldelim}`, `{rdelim}`](../language-builtin-functions/language-function-ldelim.md) tags or
43
[`{$smarty.ldelim}`,`{$smarty.rdelim}`](#language.variables.smarty.ldelim)
42
[`{$smarty.ldelim}`,`{$smarty.rdelim}`](../language-variables/language-variables-smarty.md#smartyldelim-smartyrdelim-languagevariablessmartyldelim)
44
variables.
43
variables.
45
 
44
 
Zeile 46... Zeile 45...
46
Smarty\'s default delimiters { and } cleanly represent presentational
45
Smarty's default delimiters { and } cleanly represent presentational
47
content. However if another set of delimiters suit your needs better,
46
content. However, if another set of delimiters suit your needs better,
48
you can change them with Smarty\'s
47
you can change them with Smarty's
49
[`$left_delimiter`](#variable.left.delimiter) and
48
[`$left_delimiter`](../../programmers/api-variables/variable-left-delimiter.md) and
50
[`$right_delimiter`](#variable.right.delimiter) values.
49
[`$right_delimiter`](../../programmers/api-variables/variable-right-delimiter.md) values.
Zeile -... Zeile 50...
-
 
50
 
-
 
51
> **Note**
Zeile 51... Zeile -...
51
 
-
 
52
> **Note**
-
 
53
>
52
>
54
> Changing delimiters affects ALL template syntax and escapement. Be
53
> Changing delimiters affects ALL template syntax and escapement. Be
55
> sure to clear out cache and compiled files if you decide to change
-
 
56
> them.
-
 
57
 
-
 
58
 
-
 
Zeile 59... Zeile 54...
59
    <?php
54
> sure to clear out cache and compiled files if you decide to change
60
 
-
 
-
 
55
> them.
-
 
56
 
61
    $smarty->left_delimiter = '<!--{';
57
```php
Zeile 62... Zeile 58...
62
    $smarty->right_delimiter = '}-->';
58
<?php
Zeile 63... Zeile 59...
63
 
59
 
64
    $smarty->assign('foo', 'bar');
60
$smarty->left_delimiter = '<!--{';
65
    $smarty->assign('name', 'Albert');
61
$smarty->right_delimiter = '}-->';
66
    $smarty->display('example.tpl');
62
 
67
 
63
$smarty->assign('foo', 'bar');
68
    ?>
64
$smarty->assign('name', 'Albert');
69
 
65
$smarty->display('example.tpl');
70
      
66
```
71
 
67
 
72
Where the template is:
-
 
73
 
68
Where the template is: