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 7. 内置函数

Smarty自带了一些内置函数。 这些内置函数是Smarty模板引擎的组成部分。 它们会被编译到PHP代码中,以取得最高的性能。

你不能建立相同名称的自定义函数; 同时你也不需要修改这些内置函数。

少数的内置函数有assign属性, 可以将函数的结果赋值给模板变量,而不是输出; 效果如同 {assign}函数。

{$var=...}

{assign}函数的缩写。你可以在模板内对变量进行赋值,或者对数组元素进行赋值。

Note

在模板中进行赋值,从根本上讲还是将程序逻辑放到显示层来进行了,在PHP端进行此操作会更好。请自行考虑。

下面是该标签的属性:

属性:

参数名称 缩写 类型 必选参数 默认值 说明
scope n/a string No n/a 变量的作用范围: 'parent','root' 或 'global'

可选标记:

名称 说明
nocache 对赋值操作不进行缓存

Example 7.1. 简单赋值


{$name='Bob'}

The value of $name is {$name}.

  

输出:


The value of $name is Bob.

  

Example 7.2. 数学运算赋值


{$running_total=$running_total+$some_array[row].some_value}

  

Example 7.3. 对数组元素赋值


{$user.name="Bob"}

  

Example 7.4. 对多维数组元素赋值


{$user.name.first="Bob"}

  

Example 7.5. 附加到数组


{$users[]="Bob"}

  

Example 7.6. 赋值的作用范围

在包含的模板内赋值的变量,在包含模板内可见。


{include file="sub_template.tpl"}
...
{* display variable assigned in sub_template *}
{$foo}<br>
...

  

上面的模板是包含了下面的模板sub_template.tpl


...
{* foo will be known also in the including template *}
{$foo="something" scope=parent}
{* bar is assigned only local in the including template *}
{$bar="value"}
...


参见{assign}{append}

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 1 plus 20? (Are you human?)

Advertisement