Subversion-Projekte lars-tiefland.laravel_shop

Revision

Zur aktuellen Revision | Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
{\$smarty} reserved variable {#language.variables.smarty}
2
============================
3
 
4
The PHP reserved `{$smarty}` variable can be used to access several
5
environment and request variables. The full list of them follows.
6
 
7
Request variables {#language.variables.smarty.request}
8
-----------------
9
 
10
The [request variables](&url.php-manual;reserved.variables) such as
11
`$_GET`, `$_POST`, `$_COOKIE`, `$_SERVER`, `$_ENV` and `$_SESSION` can
12
be accessed as demonstrated in the examples below:
13
 
14
 
15
    {* display value of page from URL ($_GET) http://www.example.com/index.php?page=foo *}
16
    {$smarty.get.page}
17
 
18
    {* display the variable "page" from a form ($_POST['page']) *}
19
    {$smarty.post.page}
20
 
21
    {* display the value of the cookie "username" ($_COOKIE['username']) *}
22
    {$smarty.cookies.username}
23
 
24
    {* display the server variable "SERVER_NAME" ($_SERVER['SERVER_NAME'])*}
25
    {$smarty.server.SERVER_NAME}
26
 
27
    {* display the system environment variable "PATH" *}
28
    {$smarty.env.PATH}
29
 
30
    {* display the php session variable "id" ($_SESSION['id']) *}
31
    {$smarty.session.id}
32
 
33
    {* display the variable "username" from merged get/post/cookies/server/env *}
34
    {$smarty.request.username}
35
 
36
 
37
 
38
> **Note**
39
>
40
> For historical reasons `{$SCRIPT_NAME}` is short-hand for
41
> `{$smarty.server.SCRIPT_NAME}`.
42
>
43
>
44
>     <a href="{$SCRIPT_NAME}?page=smarty">click me</a>
45
>     <a href="{$smarty.server.SCRIPT_NAME}?page=smarty">click me</a>
46
 
47
> **Note**
48
>
49
> Although Smarty provides direct access to PHP super globals for
50
> convenience, it should be used with caution. Directly accessing super
51
> globals mixes underlying application code structure with templates. A
52
> good practice is to assign specific needed values to template vars.
53
 
54
{\$smarty.now} {#language.variables.smarty.now}
55
--------------
56
 
57
The current [timestamp](&url.php-manual;function.time) can be accessed
58
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
60
to the [`date_format`](#language.modifier.date.format) modifier for
61
display. Note that [`time()`](&url.php-manual;function.time) is called
62
on each invocation; eg a script that takes three seconds to execute with
63
a call to `$smarty.now` at start and end will show the three second
64
difference.
65
 
66
::: {.informalexample}
67
 
68
    {* use the date_format modifier to show current date and time *}
69
    {$smarty.now|date_format:'%Y-%m-%d %H:%M:%S'}
70
 
71
 
72
:::
73
 
74
{\$smarty.const} {#language.variables.smarty.const}
75
----------------
76
 
77
You can access PHP constant values directly. See also [smarty
78
constants](#smarty.constants).
79
 
80
::: {.informalexample}
81
 
82
    <?php
83
    // the constant defined in php
84
    define('MY_CONST_VAL','CHERRIES');
85
    ?>
86
:::
87
 
88
Output the constant in a template with
89
 
90
::: {.informalexample}
91
 
92
    {$smarty.const.MY_CONST_VAL}
93
:::
94
 
95
> **Note**
96
>
97
> Although Smarty provides direct access to PHP constants for
98
> convenience, it is typically avoided as this is mixing underlying
99
> application code structure into the templates. A good practice is to
100
> assign specific needed values to template vars.
101
 
102
{\$smarty.capture} {#language.variables.smarty.capture}
103
------------------
104
 
105
Template output captured via the built-in
106
[`{capture}..{/capture}`](#language.function.capture) function can be
107
accessed using the `{$smarty.capture}` variable. See the
108
[`{capture}`](#language.function.capture) page for more information.
109
 
110
{\$smarty.config} {#language.variables.smarty.config}
111
-----------------
112
 
113
`{$smarty.config}` variable can be used to refer to loaded [config
114
variables](#language.config.variables). `{$smarty.config.foo}` is a
115
synonym for `{#foo#}`. See the
116
[{config\_load}](#language.function.config.load) page for more info.
117
 
118
{\$smarty.section} {#language.variables.smarty.loops}
119
------------------
120
 
121
The `{$smarty.section}` variables can be used to refer to
122
[`{section}`](#language.function.section) loop properties. These have
123
some very useful values such as `.first`, `.index`, etc.
124
 
125
> **Note**
126
>
127
> The `{$smarty.foreach}` variable is no longer used with the new
128
> [`{foreach}`](#language.function.foreach) syntax, but is still
129
> supported with Smarty 2.x style foreach syntax.
130
 
131
{\$smarty.template} {#language.variables.smarty.template}
132
-------------------
133
 
134
Returns the name of the current template being processed (without the
135
directory).
136
 
137
{\$smarty.template\_object} {#language.variables.smarty.template_object}
138
---------------------------
139
 
140
Returns the template object of the current template being processed.
141
 
142
{\$smarty.current\_dir} {#language.variables.smarty.current_dir}
143
-----------------------
144
 
145
Returns the name of the directory for the current template being
146
processed.
147
 
148
{\$smarty.version} {#language.variables.smarty.version}
149
------------------
150
 
151
Returns the version of Smarty the template was compiled with.
152
 
153
 
154
    <div id="footer">Powered by Smarty {$smarty.version}</div>
155
 
156
{\$smarty.block.child} {#language.variables.smarty.block.child}
157
----------------------
158
 
159
Returns block text from child template. See [Template
160
inheritance](#advanced.features.template.inheritance).
161
 
162
{\$smarty.block.parent} {#language.variables.smarty.block.parent}
163
-----------------------
164
 
165
Returns block text from parent template. See [Template
166
inheritance](#advanced.features.template.inheritance)
167
 
168
{\$smarty.ldelim}, {\$smarty.rdelim} {#language.variables.smarty.ldelim}
169
------------------------------------
170
 
171
These variables are used for printing the left-delimiter and
172
right-delimiter value literally, the same as
173
[`{ldelim},{rdelim}`](#language.function.ldelim).
174
 
175
See also [assigned variables](#language.assigned.variables) and [config
176
variables](#language.config.variables)