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
Variables assigned from PHP {#language.assigned.variables}
1
# Variables assigned from PHP
2
===========================
-
 
Zeile 3... Zeile 2...
3
 
2
 
4
Assigned variables that are referenced by preceding them with a dollar
3
Variables assigned from PHP are referenced by preceding them with a dollar
Zeile 5... Zeile 4...
5
(`$`) sign.
4
(`$`) sign.
Zeile -... Zeile 5...
-
 
5
 
-
 
6
## Examples
Zeile 6... Zeile 7...
6
 
7
 
Zeile -... Zeile 8...
-
 
8
```php
7
PHP code
9
<?php
-
 
10
 
Zeile 8... Zeile 11...
8
 
11
$smarty = new Smarty();
9
 
-
 
10
    <?php
-
 
Zeile 11... Zeile -...
11
 
-
 
12
    $smarty = new Smarty();
12
 
13
 
-
 
Zeile 14... Zeile 13...
14
    $smarty->assign('firstname', 'Doug');
13
$smarty->assign('firstname', 'Doug');
Zeile 15... Zeile 14...
15
    $smarty->assign('lastname', 'Evans');
14
$smarty->assign('lastname', 'Evans');
16
    $smarty->assign('meetingPlace', 'New York');
15
$smarty->assign('meetingPlace', 'New York');
17
 
16
 
18
    $smarty->display('index.tpl');
17
$smarty->display('index.tpl');
19
 
18
 
20
    ?>
19
```
21
 
20
 
22
`index.tpl` source:
21
`index.tpl` source:
Zeile 23... Zeile -...
23
 
-
 
24
 
22
 
Zeile 25... Zeile 23...
25
    Hello {$firstname} {$lastname}, glad to see you can make it.
23
```smarty
26
    <br />
24
Hello {$firstname} {$lastname}, glad to see you can make it.
27
    {* this will not work as $variables are case sensitive *}
25
<br />
28
    This weeks meeting is in {$meetingplace}.
26
{* this will not work as $variables are case sensitive *}
29
    {* this will work *}
27
This weeks meeting is in {$meetingplace}.
30
    This weeks meeting is in {$meetingPlace}.
28
{* this will work *}
Zeile 31... Zeile -...
31
 
-
 
32
       
29
This weeks meeting is in {$meetingPlace}.
33
 
-
 
Zeile 34... Zeile 30...
34
This above would output:
30
```
35
 
31
       
36
 
-
 
Zeile -... Zeile 32...
-
 
32
This above would output:
37
    Hello Doug Evans, glad to see you can make it.
33
 
38
    <br />
34
```html
39
    This weeks meeting is in .
35
Hello Doug Evans, glad to see you can make it.
40
    This weeks meeting is in New York.
36
<br />
41
 
37
This weeks meeting is in .
42
      
38
This weeks meeting is in New York.
43
 
39
```
44
Associative arrays {#language.variables.assoc.arrays}
40
      
45
------------------
41
## Associative arrays
46
 
-
 
47
You can also reference associative array variables by specifying the key
-
 
48
after a dot \".\" symbol.
42
 
Zeile 49... Zeile 43...
49
 
43
You can also reference associative array variables by specifying the key
Zeile 50... Zeile 44...
50
 
44
after a dot "." symbol.
51
    <?php
45
 
52
    $smarty->assign('Contacts',
46
```php
53
        array('fax' => '555-222-9876',
47
<?php
54
              'email' => 'zaphod@slartibartfast.example.com',
48
$smarty->assign('Contacts',
55
              'phone' => array('home' => '555-444-3333',
49
    array('fax' => '555-222-9876',
56
                               'cell' => '555-111-1234')
-
 
57
                               )
50
          'email' => 'zaphod@slartibartfast.example.com',
Zeile 58... Zeile 51...
58
             );
51
          'phone' => array('home' => '555-444-3333',
Zeile -... Zeile 52...
-
 
52
                           'cell' => '555-111-1234')
-
 
53
                           )
-
 
54
         );
-
 
55
$smarty->display('index.tpl');
-
 
56
```
-
 
57
 
Zeile 59... Zeile -...
59
    $smarty->display('index.tpl');
-
 
60
    ?>
-
 
61
 
-
 
62
       
-
 
63
 
-
 
64
`index.tpl` source:
-
 
65
 
-
 
66
 
-
 
67
    {$Contacts.fax}<br />
58
`index.tpl` source:
Zeile 68... Zeile 59...
68
    {$Contacts.email}<br />
59
 
Zeile 69... Zeile 60...
69
    {* you can print arrays of arrays as well *}
60
```smarty
70
    {$Contacts.phone.home}<br />
61
{$Contacts.fax}<br />
71
    {$Contacts.phone.cell}<br />
62
{$Contacts.email}<br />
72
 
63
{* you can print arrays of arrays as well *}
73
       
64
{$Contacts.phone.home}<br />
74
 
65
{$Contacts.phone.cell}<br />
75
this will output:
66
```
76
 
67
 
77
 
68
this will output:
78
    555-222-9876<br />
-
 
79
    zaphod@slartibartfast.example.com<br />
-
 
80
    555-444-3333<br />
69
 
Zeile 81... Zeile 70...
81
    555-111-1234<br />
70
```html
Zeile 82... Zeile 71...
82
 
71
555-222-9876<br />
83
       
72
zaphod@slartibartfast.example.com<br />
84
 
73
555-444-3333<br />
85
Array indexes {#language.variables.array.indexes}
74
555-111-1234<br />
86
-------------
75
```
87
 
76
 
88
You can reference arrays by their index, much like native PHP syntax.
-
 
89
 
77
## Array indexes
Zeile 90... Zeile 78...
90
 
78
 
Zeile -... Zeile 79...
-
 
79
You can reference arrays by their index, much like native PHP syntax.
-
 
80
 
-
 
81
```php
-
 
82
<?php
-
 
83
$smarty->assign('Contacts', array(
-
 
84
                           '555-222-9876',
Zeile 91... Zeile -...
91
    <?php
-
 
92
    $smarty->assign('Contacts', array(
-
 
93
                               '555-222-9876',
-
 
94
                               'zaphod@slartibartfast.example.com',
85
                           'zaphod@slartibartfast.example.com',
95
                                array('555-444-3333',
-
 
96
                                      '555-111-1234')
-
 
Zeile 97... Zeile -...
97
                                ));
-
 
98
    $smarty->display('index.tpl');
-
 
99
    ?>
-
 
100
 
86
                            array('555-444-3333',
101
       
87
                                  '555-111-1234')
Zeile 102... Zeile 88...
102
 
88
                            ));
103
`index.tpl` source:
89
$smarty->display('index.tpl');
104
 
90
```
105
 
-
 
106
    {$Contacts[0]}<br />
91
 
Zeile 107... Zeile 92...
107
    {$Contacts[1]}<br />
92
`index.tpl` source:
Zeile 108... Zeile 93...
108
    {* you can print arrays of arrays as well *}
93
 
109
    {$Contacts[2][0]}<br />
94
```smarty
110
    {$Contacts[2][1]}<br />
95
{$Contacts[0]}<br />
111
 
-
 
112
       
96
{$Contacts[1]}<br />
113
 
97
{* you can print arrays of arrays as well *}