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可以识别出在双引号中嵌套的 变量,这些变量名称必须只包括 字母、数字和下划线。 参见命名规则

  • 另外,带有其他字符的,如点号(.)或者 $object->reference形式的变量, 必须用`单引号`括起来。

  • Smarty3中允许在双引号中嵌入Smarty的标签并运行。 如果你需要在双引号的变量上使用修饰器、插件或者PHP函数等,这是非常有用的。

Example 3.5. 例子


{func var="test $foo test"}              // 识别变量 $foo
{func var="test $foo_bar test"}          // 识别变量 $foo_bar
{func var="test `$foo[0]` test"}         // 识别变量 $foo[0]
{func var="test `$foo[bar]` test"}       // 识别变量 $foo[bar]
{func var="test $foo.bar test"}          // 识别变量 $foo (不是 $foo.bar)
{func var="test `$foo.bar` test"}        // 识别变量 $foo.bar
{func var="test `$foo.bar` test"|escape} // 引号外的修饰器!
{func var="test {$foo|escape} test"}     // 引号内的修饰器!
{func var="test {time()} test"}          // PHP函数结果
{func var="test {counter} test"}         // 插件的结果
{func var="variable foo is {if !$foo}not {/if} defined"} // Smarty区块函数

  

Example 3.6. 例子


{* 将使用$tpl_name的值 *}
{include file="subdir/$tpl_name.tpl"}

{* 不使用$tpl_name的值 *}
{include file='subdir/$tpl_name.tpl'} // 必须用双引号才能用变量值!

{* 当变量包含了点号“.”,必须用单引号括起来 *}
{cycle values="one,two,`$smarty.config.myval`"}

{* 当变量包含了点号“.”,必须用单引号括起来 *}
{include file="`$module.contact`.tpl"}

{* 点号后面跟着变量 *}
{include file="`$module.$view`.tpl"}

  

Note

虽然Smarty能处理比较复杂的表达式和语法,但是最好保持模板语法的简洁, 把关注的焦点放在显示层面。如果你发现模板语法非常复杂,那么 最好把这些逻辑代码转移到插件或者修饰器上,用PHP代码进行编写。

参见字符转换

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 14 plus 12? (Are you human?)

Advertisement