Dev-Umgebung: Kompatibilität für PHP 8.3 + Smarty 4.5.6
- Smarty 4.1.1 → 4.5.6 (behebt dynamic property deprecations) - Core-Klassen: #[\AllowDynamicProperties] für Admin_role, base, Config, Customer, Customer_group, CustomerGroups, Item, Structure, website - website.class.php: counts[parent_id] initialisieren vor ++ (PHP 8.1) - layout.class.php: HTTP_ACCEPT_LANGUAGE mit isset-Guard - website_init.php: session_status()-Check vor session_start - .htaccess: HTTPS-Redirect via X-Forwarded-Proto (statt SERVER_PORT) - themes/easyshop_advanced/media/: Parent-Theme-Assets nachgezogen - .gitignore: smarty.4.1.1.bak ausschließen
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
# Variables
|
||||
|
||||
Smarty has several types of variables. The type of the
|
||||
variable depends on what symbol it is prefixed or enclosed within.
|
||||
|
||||
- [Variables assigned from PHP](language-assigned-variables.md)
|
||||
- [Variables loaded from config files](language-config-variables.md)
|
||||
- [{$smarty} reserved variable](language-variables-smarty.md)
|
||||
|
||||
Variables in Smarty can be either displayed directly or used as
|
||||
arguments for [functions](../language-basic-syntax/language-syntax-functions.md),
|
||||
[attributes](../language-basic-syntax/language-syntax-attributes.md) and
|
||||
[modifiers](../language-modifiers/index.md), inside conditional expressions, etc.
|
||||
To print a variable, simply enclose it in the
|
||||
[delimiters](../../programmers/api-variables/variable-left-delimiter.md) so that it is the only thing
|
||||
contained between them.
|
||||
|
||||
```smarty
|
||||
{$Name}
|
||||
|
||||
{$product.part_no} <b>{$product.description}</b>
|
||||
|
||||
{$Contacts[row].Phone}
|
||||
|
||||
<body bgcolor="{#bgcolor#}">
|
||||
```
|
||||
|
||||
## Scopes
|
||||
You can assign variables to specific [variable scopes](language-variable-scopes.md).
|
||||
|
||||
|
||||
> **Note**
|
||||
>
|
||||
> An easy way to examine assigned Smarty variables is with the
|
||||
> [debugging console](../chapter-debugging-console.md).
|
||||
|
||||
@@ -0,0 +1,126 @@
|
||||
# Variables assigned from PHP
|
||||
|
||||
Variables assigned from PHP are referenced by preceding them with a dollar
|
||||
(`$`) sign.
|
||||
|
||||
## Examples
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
$smarty = new Smarty();
|
||||
|
||||
$smarty->assign('firstname', 'Doug');
|
||||
$smarty->assign('lastname', 'Evans');
|
||||
$smarty->assign('meetingPlace', 'New York');
|
||||
|
||||
$smarty->display('index.tpl');
|
||||
|
||||
```
|
||||
|
||||
`index.tpl` source:
|
||||
|
||||
```smarty
|
||||
Hello {$firstname} {$lastname}, glad to see you can make it.
|
||||
<br />
|
||||
{* this will not work as $variables are case sensitive *}
|
||||
This weeks meeting is in {$meetingplace}.
|
||||
{* this will work *}
|
||||
This weeks meeting is in {$meetingPlace}.
|
||||
```
|
||||
|
||||
This above would output:
|
||||
|
||||
```html
|
||||
Hello Doug Evans, glad to see you can make it.
|
||||
<br />
|
||||
This weeks meeting is in .
|
||||
This weeks meeting is in New York.
|
||||
```
|
||||
|
||||
## Associative arrays
|
||||
|
||||
You can also reference associative array variables by specifying the key
|
||||
after a dot "." symbol.
|
||||
|
||||
```php
|
||||
<?php
|
||||
$smarty->assign('Contacts',
|
||||
array('fax' => '555-222-9876',
|
||||
'email' => 'zaphod@slartibartfast.example.com',
|
||||
'phone' => array('home' => '555-444-3333',
|
||||
'cell' => '555-111-1234')
|
||||
)
|
||||
);
|
||||
$smarty->display('index.tpl');
|
||||
```
|
||||
|
||||
`index.tpl` source:
|
||||
|
||||
```smarty
|
||||
{$Contacts.fax}<br />
|
||||
{$Contacts.email}<br />
|
||||
{* you can print arrays of arrays as well *}
|
||||
{$Contacts.phone.home}<br />
|
||||
{$Contacts.phone.cell}<br />
|
||||
```
|
||||
|
||||
this will output:
|
||||
|
||||
```html
|
||||
555-222-9876<br />
|
||||
zaphod@slartibartfast.example.com<br />
|
||||
555-444-3333<br />
|
||||
555-111-1234<br />
|
||||
```
|
||||
|
||||
## Array indexes
|
||||
|
||||
You can reference arrays by their index, much like native PHP syntax.
|
||||
|
||||
```php
|
||||
<?php
|
||||
$smarty->assign('Contacts', array(
|
||||
'555-222-9876',
|
||||
'zaphod@slartibartfast.example.com',
|
||||
array('555-444-3333',
|
||||
'555-111-1234')
|
||||
));
|
||||
$smarty->display('index.tpl');
|
||||
```
|
||||
|
||||
`index.tpl` source:
|
||||
|
||||
```smarty
|
||||
{$Contacts[0]}<br />
|
||||
{$Contacts[1]}<br />
|
||||
{* you can print arrays of arrays as well *}
|
||||
{$Contacts[2][0]}<br />
|
||||
{$Contacts[2][1]}<br />
|
||||
```
|
||||
|
||||
This will output:
|
||||
|
||||
```html
|
||||
555-222-9876<br />
|
||||
zaphod@slartibartfast.example.com<br />
|
||||
555-444-3333<br />
|
||||
555-111-1234<br />
|
||||
```
|
||||
|
||||
## Objects
|
||||
|
||||
Properties of [objects](../../programmers/advanced-features/advanced-features-objects.md) assigned from PHP
|
||||
can be referenced by specifying the property name after the `->` symbol.
|
||||
|
||||
```smarty
|
||||
name: {$person->name}<br />
|
||||
email: {$person->email}<br />
|
||||
```
|
||||
|
||||
this will output:
|
||||
|
||||
```html
|
||||
name: Zaphod Beeblebrox<br />
|
||||
email: zaphod@slartibartfast.example.com<br />
|
||||
```
|
||||
@@ -0,0 +1,79 @@
|
||||
# Variables loaded from config files
|
||||
|
||||
Variables that are loaded from the [config files](../config-files.md) are
|
||||
referenced by enclosing them within `#hash_marks#`, or with the smarty
|
||||
variable [`$smarty.config`](language-variables-smarty.md#smartyconfig-languagevariablessmartyconfig). The
|
||||
later syntax is useful for embedding into quoted attribute values, or
|
||||
accessing variable values such as `$smarty.config.$foo`.
|
||||
|
||||
## Examples
|
||||
|
||||
Example config file - `foo.conf`:
|
||||
```ini
|
||||
pageTitle = "This is mine"
|
||||
bodyBgColor = '#eeeeee'
|
||||
tableBorderSize = 3
|
||||
tableBgColor = "#bbbbbb"
|
||||
rowBgColor = "#cccccc"
|
||||
```
|
||||
|
||||
A template demonstrating the `#hash#` method:
|
||||
|
||||
```smarty
|
||||
{config_load file='foo.conf'}
|
||||
<html>
|
||||
<title>{#pageTitle#}</title>
|
||||
<body bgcolor="{#bodyBgColor#}">
|
||||
<table border="{#tableBorderSize#}" bgcolor="{#tableBgColor#}">
|
||||
<tr bgcolor="{#rowBgColor#}">
|
||||
<td>First</td>
|
||||
<td>Last</td>
|
||||
<td>Address</td>
|
||||
</tr>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
|
||||
A template demonstrating the
|
||||
[`$smarty.config`](language-variables-smarty.md#smartyconfig-languagevariablessmartyconfig) method:
|
||||
|
||||
```smarty
|
||||
{config_load file='foo.conf'}
|
||||
<html>
|
||||
<title>{$smarty.config.pageTitle}</title>
|
||||
<body bgcolor="{$smarty.config.bodyBgColor}">
|
||||
<table border="{$smarty.config.tableBorderSize}" bgcolor="{$smarty.config.tableBgColor}">
|
||||
<tr bgcolor="{$smarty.config.rowBgColor}">
|
||||
<td>First</td>
|
||||
<td>Last</td>
|
||||
<td>Address</td>
|
||||
</tr>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
|
||||
Both examples would output:
|
||||
|
||||
```html
|
||||
<html>
|
||||
<title>This is mine</title>
|
||||
<body bgcolor="#eeeeee">
|
||||
<table border="3" bgcolor="#bbbbbb">
|
||||
<tr bgcolor="#cccccc">
|
||||
<td>First</td>
|
||||
<td>Last</td>
|
||||
<td>Address</td>
|
||||
</tr>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
|
||||
Config file variables cannot be used until after they are loaded in from
|
||||
a config file. This procedure is explained later in this document under
|
||||
[`{config_load}`](../language-builtin-functions/language-function-config-load.md).
|
||||
|
||||
See also [variables](../language-basic-syntax/language-syntax-variables.md) and [$smarty reserved
|
||||
variables](language-variables-smarty.md).
|
||||
@@ -0,0 +1,60 @@
|
||||
# Variable scopes
|
||||
|
||||
You have the choice to assign variables to the scope of the main Smarty
|
||||
object, data objects created with [`createData()`](../../programmers/api-functions/api-create-data.md),
|
||||
and template objects created with
|
||||
[`createTemplate()`](../../programmers/api-functions/api-create-template.md). These objects can be
|
||||
chained. A template sees all the variables of its own object and all
|
||||
variables assigned to the objects in its chain of parent objects.
|
||||
|
||||
By default, templates which are rendered by
|
||||
[`$smarty->display(...)`](../../programmers/api-functions/api-display.md) or
|
||||
[`$smarty->fetch(...)`](../../programmers/api-functions/api-fetch.md) calls are automatically linked to
|
||||
the Smarty object variable scope.
|
||||
|
||||
By assigning variables to individual data or template objects you have
|
||||
full control which variables can be seen by a template.
|
||||
|
||||
```php
|
||||
<?php
|
||||
// assign variable to Smarty object scope
|
||||
$smarty->assign('foo','smarty');
|
||||
|
||||
// assign variables to data object scope
|
||||
$data = $smarty->createData();
|
||||
$data->assign('foo','data');
|
||||
$data->assign('bar','bar-data');
|
||||
|
||||
// assign variables to other data object scope
|
||||
$data2 = $smarty->createData($data);
|
||||
$data2->assign('bar','bar-data2');
|
||||
|
||||
// assign variable to template object scope
|
||||
$tpl = $smarty->createTemplate('index.tpl');
|
||||
$tpl->assign('bar','bar-template');
|
||||
|
||||
// assign variable to template object scope with link to Smarty object
|
||||
$tpl2 = $smarty->createTemplate('index.tpl',$smarty);
|
||||
$tpl2->assign('bar','bar-template2');
|
||||
|
||||
// This display() does see $foo='smarty' from the $smarty object
|
||||
$smarty->display('index.tpl');
|
||||
|
||||
// This display() does see $foo='data' and $bar='bar-data' from the data object $data
|
||||
$smarty->display('index.tpl',$data);
|
||||
|
||||
// This display() does see $foo='data' from the data object $data
|
||||
// and $bar='bar-data2' from the data object $data2
|
||||
$smarty->display('index.tpl',$data2);
|
||||
|
||||
// This display() does see $bar='bar-template' from the template object $tpl
|
||||
$tpl->display(); // or $smarty->display($tpl);
|
||||
|
||||
// This display() does see $bar='bar-template2' from the template object $tpl2
|
||||
// and $foo='smarty' form the Smarty object $foo
|
||||
$tpl2->display(); // or $smarty->display($tpl2);
|
||||
```
|
||||
|
||||
See also [`assign()`](../../programmers/api-functions/api-assign.md),
|
||||
[`createData()`](../../programmers/api-functions/api-create-data.md)
|
||||
and [`createTemplate()`](../../programmers/api-functions/api-create-template.md).
|
||||
@@ -0,0 +1,156 @@
|
||||
# {$smarty} reserved variable
|
||||
|
||||
The PHP reserved `{$smarty}` variable can be used to access several
|
||||
environment and request variables. The full list of them follows.
|
||||
|
||||
## Request variables
|
||||
|
||||
The [request variables](https://www.php.net/reserved.variables) such as
|
||||
`$_GET`, `$_POST`, `$_COOKIE`, `$_SERVER`, `$_ENV` and `$_SESSION` can
|
||||
be accessed as demonstrated in the examples below:
|
||||
|
||||
```smarty
|
||||
{* display value of page from URL ($_GET) http://www.example.com/index.php?page=foo *}
|
||||
{$smarty.get.page}
|
||||
|
||||
{* display the variable "page" from a form ($_POST['page']) *}
|
||||
{$smarty.post.page}
|
||||
|
||||
{* display the value of the cookie "username" ($_COOKIE['username']) *}
|
||||
{$smarty.cookies.username}
|
||||
|
||||
{* display the server variable "SERVER_NAME" ($_SERVER['SERVER_NAME'])*}
|
||||
{$smarty.server.SERVER_NAME}
|
||||
|
||||
{* display the system environment variable "PATH" *}
|
||||
{$smarty.env.PATH}
|
||||
|
||||
{* display the php session variable "id" ($_SESSION['id']) *}
|
||||
{$smarty.session.id}
|
||||
|
||||
{* display the variable "username" from merged get/post/cookies/server/env *}
|
||||
{$smarty.request.username}
|
||||
```
|
||||
|
||||
> **Note**
|
||||
>
|
||||
> For historical reasons `{$SCRIPT_NAME}` is shorthand for
|
||||
> `{$smarty.server.SCRIPT_NAME}`.
|
||||
>
|
||||
>
|
||||
> <a href="{$SCRIPT_NAME}?page=smarty">click me</a>
|
||||
> <a href="{$smarty.server.SCRIPT_NAME}?page=smarty">click me</a>
|
||||
|
||||
> **Note**
|
||||
>
|
||||
> Although Smarty provides direct access to PHP super globals for
|
||||
> convenience, it should be used with caution. Directly accessing super
|
||||
> globals mixes underlying application code structure with templates. A
|
||||
> good practice is to assign specific needed values to template vars.
|
||||
|
||||
## {$smarty.now}
|
||||
|
||||
The current [timestamp](https://www.php.net/function.time) can be accessed
|
||||
with `{$smarty.now}`. The value reflects the number of seconds passed
|
||||
since the so-called Epoch on January 1, 1970, and can be passed directly
|
||||
to the [`date_format`](../language-modifiers/language-modifier-date-format.md) modifier for
|
||||
display. Note that [`time()`](https://www.php.net/function.time) is called
|
||||
on each invocation; eg a script that takes three seconds to execute with
|
||||
a call to `$smarty.now` at start and end will show the three-second
|
||||
difference.
|
||||
|
||||
```smarty
|
||||
{* use the date_format modifier to show current date and time *}
|
||||
{$smarty.now|date_format:'%Y-%m-%d %H:%M:%S'}
|
||||
```
|
||||
|
||||
## {$smarty.const}
|
||||
|
||||
You can access PHP constant values directly. See also [smarty
|
||||
constants](../../programmers/smarty-constants.md).
|
||||
|
||||
```php
|
||||
<?php
|
||||
// the constant defined in php
|
||||
define('MY_CONST_VAL','CHERRIES');
|
||||
```
|
||||
|
||||
Output the constant in a template with
|
||||
|
||||
```smarty
|
||||
{$smarty.const.MY_CONST_VAL}
|
||||
```
|
||||
|
||||
> **Note**
|
||||
>
|
||||
> Although Smarty provides direct access to PHP constants for
|
||||
> convenience, it is typically avoided as this is mixing underlying
|
||||
> application code structure into the templates. A good practice is to
|
||||
> assign specific needed values to template vars.
|
||||
|
||||
## {$smarty.capture}
|
||||
|
||||
Template output captured via the built-in
|
||||
[`{capture}..{/capture}`](../language-builtin-functions/language-function-capture.md) function can be
|
||||
accessed using the `{$smarty.capture}` variable. See the
|
||||
[`{capture}`](../language-builtin-functions/language-function-capture.md) page for more information.
|
||||
|
||||
## {$smarty.config}
|
||||
|
||||
`{$smarty.config}` variable can be used to refer to loaded [config
|
||||
variables](language-config-variables.md). `{$smarty.config.foo}` is a
|
||||
synonym for `{#foo#}`. See the
|
||||
[{config_load}](../language-builtin-functions/language-function-config-load.md) page for more info.
|
||||
|
||||
## {$smarty.section}
|
||||
|
||||
The `{$smarty.section}` variables can be used to refer to
|
||||
[`{section}`](../language-builtin-functions/language-function-section.md) loop properties. These have
|
||||
some very useful values such as `.first`, `.index`, etc.
|
||||
|
||||
> **Note**
|
||||
>
|
||||
> The `{$smarty.foreach}` variable is no longer used with the new
|
||||
> [`{foreach}`](../language-builtin-functions/language-function-foreach.md) syntax, but is still
|
||||
> supported with Smarty 2.x style foreach syntax.
|
||||
|
||||
## {$smarty.template}
|
||||
|
||||
Returns the name of the current template being processed (without the
|
||||
directory).
|
||||
|
||||
## {$smarty.template_object}
|
||||
|
||||
Returns the template object of the current template being processed.
|
||||
|
||||
## {$smarty.current_dir}
|
||||
|
||||
Returns the name of the directory for the current template being
|
||||
processed if it is loaded from the filesystem (the default).
|
||||
|
||||
## {$smarty.version}
|
||||
|
||||
Returns the version of Smarty the template was compiled with.
|
||||
|
||||
```smarty
|
||||
<div id="footer">Powered by Smarty {$smarty.version}</div>
|
||||
```
|
||||
|
||||
## {$smarty.block.child}
|
||||
|
||||
Returns block text from child template. See [Template
|
||||
inheritance](../../programmers/advanced-features/advanced-features-template-inheritance.md).
|
||||
|
||||
## {$smarty.block.parent}
|
||||
|
||||
Returns block text from parent template. See [Template
|
||||
inheritance](../../programmers/advanced-features/advanced-features-template-inheritance.md)
|
||||
|
||||
## {$smarty.ldelim}, {$smarty.rdelim}
|
||||
|
||||
These variables are used for printing the left-delimiter and
|
||||
right-delimiter value literally, the same as
|
||||
[`{ldelim},{rdelim}`](../language-builtin-functions/language-function-ldelim.md).
|
||||
|
||||
See also [assigned variables](language-assigned-variables.md) and [config
|
||||
variables](language-config-variables.md)
|
||||
Reference in New Issue
Block a user