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
{\$smarty} reserved variable {#language.variables.smarty}
1
# {$smarty} reserved variable
2
============================
-
 
Zeile 3... Zeile 2...
3
 
2
 
4
The PHP reserved `{$smarty}` variable can be used to access several
3
The PHP reserved `{$smarty}` variable can be used to access several
Zeile 5... Zeile -...
5
environment and request variables. The full list of them follows.
-
 
6
 
4
environment and request variables. The full list of them follows.
Zeile 7... Zeile 5...
7
Request variables {#language.variables.smarty.request}
5
 
8
-----------------
6
## Request variables
9
 
7
 
Zeile -... Zeile 8...
-
 
8
The [request variables](https://www.php.net/reserved.variables) such as
-
 
9
`$_GET`, `$_POST`, `$_COOKIE`, `$_SERVER`, `$_ENV` and `$_SESSION` can
-
 
10
be accessed as demonstrated in the examples below:
Zeile 10... Zeile 11...
10
The [request variables](&url.php-manual;reserved.variables) such as
11
 
11
`$_GET`, `$_POST`, `$_COOKIE`, `$_SERVER`, `$_ENV` and `$_SESSION` can
12
```smarty
Zeile 12... Zeile 13...
12
be accessed as demonstrated in the examples below:
13
{* display value of page from URL ($_GET) http://www.example.com/index.php?page=foo *}
13
 
14
{$smarty.get.page}
Zeile 14... Zeile 15...
14
 
15
 
15
    {* display value of page from URL ($_GET) http://www.example.com/index.php?page=foo *}
16
{* display the variable "page" from a form ($_POST['page']) *}
Zeile 16... Zeile 17...
16
    {$smarty.get.page}
17
{$smarty.post.page}
17
 
18
 
Zeile 18... Zeile 19...
18
    {* display the variable "page" from a form ($_POST['page']) *}
19
{* display the value of the cookie "username" ($_COOKIE['username']) *}
19
    {$smarty.post.page}
20
{$smarty.cookies.username}
Zeile 20... Zeile -...
20
 
-
 
21
    {* display the value of the cookie "username" ($_COOKIE['username']) *}
-
 
22
    {$smarty.cookies.username}
-
 
23
 
21
 
24
    {* display the server variable "SERVER_NAME" ($_SERVER['SERVER_NAME'])*}
22
{* display the server variable "SERVER_NAME" ($_SERVER['SERVER_NAME'])*}
25
    {$smarty.server.SERVER_NAME}
-
 
26
 
23
{$smarty.server.SERVER_NAME}
Zeile 27... Zeile 24...
27
    {* display the system environment variable "PATH" *}
24
 
28
    {$smarty.env.PATH}
25
{* display the system environment variable "PATH" *}
29
 
26
{$smarty.env.PATH}
30
    {* display the php session variable "id" ($_SESSION['id']) *}
27
 
31
    {$smarty.session.id}
28
{* display the php session variable "id" ($_SESSION['id']) *}
32
 
29
{$smarty.session.id}
33
    {* display the variable "username" from merged get/post/cookies/server/env *}
30
 
34
    {$smarty.request.username}
31
{* display the variable "username" from merged get/post/cookies/server/env *}
Zeile 49... Zeile 46...
49
> Although Smarty provides direct access to PHP super globals for
46
> Although Smarty provides direct access to PHP super globals for
50
> convenience, it should be used with caution. Directly accessing super
47
> convenience, it should be used with caution. Directly accessing super
51
> globals mixes underlying application code structure with templates. A
48
> globals mixes underlying application code structure with templates. A
52
> good practice is to assign specific needed values to template vars.
49
> good practice is to assign specific needed values to template vars.
Zeile 53... Zeile -...
53
 
-
 
54
{\$smarty.now} {#language.variables.smarty.now}
50
 
Zeile 55... Zeile 51...
55
--------------
51
## {$smarty.now}
56
 
52
 
57
The current [timestamp](&url.php-manual;function.time) can be accessed
53
The current [timestamp](https://www.php.net/function.time) can be accessed
58
with `{$smarty.now}`. The value reflects the number of seconds passed
54
with `{$smarty.now}`. The value reflects the number of seconds passed
59
since the so-called Epoch on January 1, 1970, and can be passed directly
55
since the so-called Epoch on January 1, 1970, and can be passed directly
60
to the [`date_format`](#language.modifier.date.format) modifier for
56
to the [`date_format`](../language-modifiers/language-modifier-date-format.md) modifier for
61
display. Note that [`time()`](&url.php-manual;function.time) is called
57
display. Note that [`time()`](https://www.php.net/function.time) is called
62
on each invocation; eg a script that takes three seconds to execute with
58
on each invocation; eg a script that takes three seconds to execute with
Zeile 63... Zeile 59...
63
a call to `$smarty.now` at start and end will show the three second
59
a call to `$smarty.now` at start and end will show the three-second
64
difference.
-
 
65
 
60
difference.
66
::: {.informalexample}
61
 
67
 
-
 
68
    {* use the date_format modifier to show current date and time *}
-
 
69
    {$smarty.now|date_format:'%Y-%m-%d %H:%M:%S'}
62
```smarty
Zeile 70... Zeile -...
70
 
-
 
71
       
63
{* use the date_format modifier to show current date and time *}
Zeile 72... Zeile 64...
72
:::
64
{$smarty.now|date_format:'%Y-%m-%d %H:%M:%S'}
73
 
65
```
Zeile 74... Zeile -...
74
{\$smarty.const} {#language.variables.smarty.const}
-
 
75
----------------
66
 
76
 
67
## {$smarty.const}
77
You can access PHP constant values directly. See also [smarty
68
 
78
constants](#smarty.constants).
69
You can access PHP constant values directly. See also [smarty
79
 
-
 
80
::: {.informalexample}
70
constants](../../programmers/smarty-constants.md).
Zeile 81... Zeile 71...
81
 
71
 
Zeile 82... Zeile 72...
82
    <?php
72
```php
83
    // the constant defined in php
-
 
84
    define('MY_CONST_VAL','CHERRIES');
73
<?php
85
    ?>
74
// the constant defined in php
Zeile 86... Zeile 75...
86
:::
75
define('MY_CONST_VAL','CHERRIES');
87
 
76
```
88
Output the constant in a template with
77
 
89
 
78
Output the constant in a template with
90
::: {.informalexample}
79
 
91
 
80
```smarty
Zeile 92... Zeile -...
92
    {$smarty.const.MY_CONST_VAL}
-
 
93
:::
81
{$smarty.const.MY_CONST_VAL}
Zeile 94... Zeile 82...
94
 
82
```
95
> **Note**
83
 
96
>
84
> **Note**
97
> Although Smarty provides direct access to PHP constants for
85
>
Zeile 98... Zeile -...
98
> convenience, it is typically avoided as this is mixing underlying
-
 
99
> application code structure into the templates. A good practice is to
86
> Although Smarty provides direct access to PHP constants for
Zeile 100... Zeile 87...
100
> assign specific needed values to template vars.
87
> convenience, it is typically avoided as this is mixing underlying
101
 
88
> application code structure into the templates. A good practice is to
102
{\$smarty.capture} {#language.variables.smarty.capture}
89
> assign specific needed values to template vars.
103
------------------
90
 
Zeile 104... Zeile -...
104
 
-
 
105
Template output captured via the built-in
91
## {$smarty.capture}
Zeile 106... Zeile 92...
106
[`{capture}..{/capture}`](#language.function.capture) function can be
92
 
107
accessed using the `{$smarty.capture}` variable. See the
93
Template output captured via the built-in
108
[`{capture}`](#language.function.capture) page for more information.
94
[`{capture}..{/capture}`](../language-builtin-functions/language-function-capture.md) function can be
Zeile 109... Zeile 95...
109
 
95
accessed using the `{$smarty.capture}` variable. See the
110
{\$smarty.config} {#language.variables.smarty.config}
96
[`{capture}`](../language-builtin-functions/language-function-capture.md) page for more information.
111
-----------------
97
 
112
 
98
## {$smarty.config}
113
`{$smarty.config}` variable can be used to refer to loaded [config
99
 
Zeile 114... Zeile 100...
114
variables](#language.config.variables). `{$smarty.config.foo}` is a
100
`{$smarty.config}` variable can be used to refer to loaded [config
115
synonym for `{#foo#}`. See the
-
 
Zeile 116... Zeile 101...
116
[{config\_load}](#language.function.config.load) page for more info.
101
variables](language-config-variables.md). `{$smarty.config.foo}` is a
117
 
102
synonym for `{#foo#}`. See the
Zeile 118... Zeile 103...
118
{\$smarty.section} {#language.variables.smarty.loops}
103
[{config_load}](../language-builtin-functions/language-function-config-load.md) page for more info.
119
------------------
-
 
Zeile 120... Zeile 104...
120
 
104
 
Zeile 121... Zeile 105...
121
The `{$smarty.section}` variables can be used to refer to
105
## {$smarty.section}
122
[`{section}`](#language.function.section) loop properties. These have
-
 
Zeile 123... Zeile 106...
123
some very useful values such as `.first`, `.index`, etc.
106
 
124
 
107
The `{$smarty.section}` variables can be used to refer to
Zeile 125... Zeile -...
125
> **Note**
-
 
126
>
108
[`{section}`](../language-builtin-functions/language-function-section.md) loop properties. These have
Zeile 127... Zeile 109...
127
> The `{$smarty.foreach}` variable is no longer used with the new
109
some very useful values such as `.first`, `.index`, etc.
Zeile -... Zeile 110...
-
 
110
 
-
 
111
> **Note**
-
 
112
>
Zeile 128... Zeile -...
128
> [`{foreach}`](#language.function.foreach) syntax, but is still
-
 
129
> supported with Smarty 2.x style foreach syntax.
-
 
130
 
113
> The `{$smarty.foreach}` variable is no longer used with the new
131
{\$smarty.template} {#language.variables.smarty.template}
-
 
Zeile 132... Zeile 114...
132
-------------------
114
> [`{foreach}`](../language-builtin-functions/language-function-foreach.md) syntax, but is still
133
 
115
> supported with Smarty 2.x style foreach syntax.
Zeile 134... Zeile 116...
134
Returns the name of the current template being processed (without the
116
 
135
directory).
-
 
Zeile 136... Zeile 117...
136
 
117
## {$smarty.template}
137
{\$smarty.template\_object} {#language.variables.smarty.template_object}
118
 
Zeile 138... Zeile 119...
138
---------------------------
119
Returns the name of the current template being processed (without the
139
 
-
 
Zeile 140... Zeile 120...
140
Returns the template object of the current template being processed.
120
directory).
141
 
121
 
142
{\$smarty.current\_dir} {#language.variables.smarty.current_dir}
122
## {$smarty.template_object}
Zeile 143... Zeile 123...
143
-----------------------
123
 
144
 
124
Returns the template object of the current template being processed.