diff options
Diffstat (limited to 'vendor/smarty/smarty/docs/designers/language-variables/language-assigned-variables.md')
-rw-r--r-- | vendor/smarty/smarty/docs/designers/language-variables/language-assigned-variables.md | 188 |
1 files changed, 86 insertions, 102 deletions
diff --git a/vendor/smarty/smarty/docs/designers/language-variables/language-assigned-variables.md b/vendor/smarty/smarty/docs/designers/language-variables/language-assigned-variables.md index 005dea4a9..bd356a2b0 100644 --- a/vendor/smarty/smarty/docs/designers/language-variables/language-assigned-variables.md +++ b/vendor/smarty/smarty/docs/designers/language-variables/language-assigned-variables.md @@ -1,142 +1,126 @@ -Variables assigned from PHP {#language.assigned.variables} -=========================== +# Variables assigned from PHP -Assigned variables that are referenced by preceding them with a dollar +Variables assigned from PHP are referenced by preceding them with a dollar (`$`) sign. -PHP code +## Examples +```php +<?php - <?php +$smarty = new Smarty(); - $smarty = new Smarty(); +$smarty->assign('firstname', 'Doug'); +$smarty->assign('lastname', 'Evans'); +$smarty->assign('meetingPlace', 'New York'); - $smarty->assign('firstname', 'Doug'); - $smarty->assign('lastname', 'Evans'); - $smarty->assign('meetingPlace', 'New York'); +$smarty->display('index.tpl'); - $smarty->display('index.tpl'); - - ?> +``` `index.tpl` source: - - 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}. - +```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: - - Hello Doug Evans, glad to see you can make it. - <br /> - This weeks meeting is in . - This weeks meeting is in New York. - +```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 {#language.variables.assoc.arrays} ------------------- +## Associative arrays You can also reference associative array variables by specifying the key -after a dot \".\" symbol. - - - <?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'); - ?> - - +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: - - {$Contacts.fax}<br /> - {$Contacts.email}<br /> - {* you can print arrays of arrays as well *} - {$Contacts.phone.home}<br /> - {$Contacts.phone.cell}<br /> - - +```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 /> +``` - 555-222-9876<br /> - zaphod@slartibartfast.example.com<br /> - 555-444-3333<br /> - 555-111-1234<br /> - - - -Array indexes {#language.variables.array.indexes} -------------- +## Array indexes You can reference arrays by their index, much like native PHP syntax. - - <?php - $smarty->assign('Contacts', array( - '555-222-9876', - 'zaphod@slartibartfast.example.com', - array('555-444-3333', - '555-111-1234') - )); - $smarty->display('index.tpl'); - ?> - - +```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: - - {$Contacts[0]}<br /> - {$Contacts[1]}<br /> - {* you can print arrays of arrays as well *} - {$Contacts[2][0]}<br /> - {$Contacts[2][1]}<br /> - - +```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 /> +``` - 555-222-9876<br /> - zaphod@slartibartfast.example.com<br /> - 555-444-3333<br /> - 555-111-1234<br /> - - - -Objects {#language.variables.objects} -------- +## Objects -Properties of [objects](#advanced.features.objects) assigned from PHP +Properties of [objects](../../programmers/advanced-features/advanced-features-objects.md) assigned from PHP can be referenced by specifying the property name after the `->` symbol. - - name: {$person->name}<br /> - email: {$person->email}<br /> - - +```smarty +name: {$person->name}<br /> +email: {$person->email}<br /> +``` this will output: - - name: Zaphod Beeblebrox<br /> - email: zaphod@slartibartfast.example.com<br /> - - +```html +name: Zaphod Beeblebrox<br /> +email: zaphod@slartibartfast.example.com<br /> +```
\ No newline at end of file |