php分配变量,从PHP分配的变量

Chapter 4. Variables[第四章.变量]

第四章.变量

Table of Contents[内容列表]

Variables assigned from PHP[从PHP分配的变量]

Variables loaded from config files[从配置文件读取的变量]

{$smarty} reserved variable[{$smarty} 保留变量]

Smarty has several different types of variables.

The type of the variable depends on what symbol it is prefixed with (or enclosed

within).

Smarty有几种不同类型的变量.

变量 的类型取决于它的前缀是什么符号(或者被什么符号包围)

Variables in Smarty can be either displayed directly or used as arguments for

function attributes and modifiers, inside conditional expressions, etc.

To print a variable, simply enclose it in the delimiters so that it is the

only thing contained between them. Examples:

Smarty的变量可以直接被输出或者作为函数属性和修饰符(modifiers)的参数,或者用于内部的条件表达式等等.

如果要输出一个变量,只要用定界符将它括起来就可以.例如:

{$Name}

{$Contacts[row].Phone}

Variables assigned from PHP

从PHP分配的变量

Table of Contents[内容列表]

Associative arrays[关联数组]

Array indexes[数组下标]

Objects[对象]

Variables that are assigned from PHP are referenced by preceding them with a

dollar sign $.

Variables assigned from within the template with the assign function are also displayed this way.

调用从PHP分配的变量需在前加"$"符号.(译注:同php一样)

调用模板内的assign函数分配的变量也是这样.(译注:也是用$加变量名来调用)

Example 4-1. assigned variables

例 4-1.分配的变量

index.php:

$smarty = new Smarty;

$smarty->assign("firstname", "Doug");

$smarty->assign("lastLoginDate", "January 11th, 2001");

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

index.tpl:

Hello {$firstname}, glad to see you could make it.

Your last login was on {$lastLoginDate}.

OUTPUT:

Hello Doug, glad to see you could make it.

Your last login was on January 11th, 2001.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值