Get Smarty

Donate

Donate Bitcoin Bitcoin
Paypal

Smarty Icon

You may use the Smarty logo according to the trademark notice.

Smarty Template Engine Smarty Template Engine

For sponsorship, advertising, news or other inquiries, contact us at:

Sites Using Smarty

Buy cheap eyeglasses from Cheapglasses123.com and save up to 80%.

Buy prescription glasses from www.australiaglasses.com and save.

Cheap Glasses Now On Sale at GlassesPeople.com. Starts At $7.95.

Where to buy discount wedding dresses and cheap smart dresses free shipping - Weddingdresstrend.com

Brautkleider auf Topwedding.de

Find free files to download on allwhatyouwant.net

Looking For Affordable Wedding Dresses 2015 at Best Prices On TDBridal.com

Shop high quality cheap prom dresses on Dresswe.co.uk

Buy New Arrival Cheap Prom Dresses 2015 at JDBRIDAL Prom Dress Store

Advertisement

Chapter 4. ��

Smarty有多�类型的��。

在Smarty中的���以直接显示,或者作为 函数, 属性 and 修饰器, 内部�件表达�等的�数。 �显示��,�以简�地用 定界符 把��括起�。

Example 4.1. ��例�


{$Name}

{$product.part_no} <b>{$product.description}</b>

{$Contacts[row].Phone}

<body bgcolor="{#bgcolor#}">

  


说明

一个简�的检查Smarty��的方法是打开Smarty的 调试控制�。

从PHP赋值的��

赋值的��以美元符� ($) 开头。

Example 4.2. ��赋值

PHP 代�


<?php

$smarty = new Smarty();

$smarty->assign('firstname', 'Doug');
$smarty->assign('lastname', 'Evans');
$smarty->assign('meetingPlace', 'New York');

$smarty->display('index.tpl');

?>

index.tpl模���:


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}.

   

输出:


Hello Doug Evans, glad to see you can make it.
<br />
This weeks meeting is in .
This weeks meeting is in New York.

  

数组赋值

�以通过点�“.��使用赋值的数组��。

Example 4.3. 数组��


<?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模�代�:


{$Contacts.fax}<br />
{$Contacts.email}<br />
{* you can print arrays of arrays as well *}
{$Contacts.phone.home}<br />
{$Contacts.phone.cell}<br />

   

输出:


555-222-9876<br />
zaphod@slartibartfast.example.com<br />
555-444-3333<br />
555-111-1234<br />

   

数组下标

你�以通过下标�使用数组,和PHP语法一样。

Example 4.4. 使用数组下标


<?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模�代�:


{$Contacts[0]}<br />
{$Contacts[1]}<br />
{* you can print arrays of arrays as well *}
{$Contacts[2][0]}<br />
{$Contacts[2][1]}<br />

   

输出:


555-222-9876<br />
zaphod@slartibartfast.example.com<br />
555-444-3333<br />
555-111-1234<br />

   

对象

从PHP赋值的对象的属性和方法,�以通过->�使用。

Example 4.5. 使用对象


name:  {$person->name}<br />
email: {$person->email}<br />

   

输出:


name:  Zaphod Beeblebrox<br />
email: zaphod@slartibartfast.example.com<br />

   

Comments
No comments for this page.
Post a Comment
All comments are moderated. Support questions are ignored, use the forums instead.
Author:
Email: (not shown)
What is 15 plus 17? (Are you human?)

Advertisement