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

变量作用范围

你可以设置Smarty对象、通过createData()建立的对象、和createTemplate()建立的对象的作用范围。 这些对象可以连接使用。 模板内可以使用全部由对象的变量和它们链条上的父对象的变量。

默认模板通过 $smarty->display(...)$smarty->fetch(...)调用,可获取到Smarty对象范围的变量。

通过传递特定的数据或模板对象,你可以完全在模板内控制这些变量的可视范围。

Example 4.6. 变量范围的例子



// 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);

    


参见assign(), createData()createTemplate().

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 19 plus 0? (Are you human?)

Advertisement