如何注册一个全局变量能在smarty模板内使用

#1 peter

本人想在smarty模板内(html文件内),使用一个全局变量,或者能使用session等值。
如何和才能做到。:dizzy:

2010-09-18 14:45:39

#2 jake

http://www.smarty.net/manual/en/language.variables.smarty.php

可以使用$smarty值,比如说常量 MYVAL 在模板中就是 $smarty.const.MYVAL
session就是$smarty.session.id等等

看看上面的文档,有更多的$smarty变量的使用方法。

2010-09-18 20:02:08

#3 peter

感谢jake ,又知道新东西了。:lol

2010-09-19 10:33:22

#4 xpp1000

比如我要判断权限是这样写还是如何写。<{ if $_SESSION["fg"]=='家长' }>欢迎你$_SESSSION["user"]家长<{/if}>
或者
。<{ if $smarty.session.fg=='家长' }>欢迎你$smarty.session.user家长<{/if}>

2010-09-30 09:00:17

#5 jake

<{ if $smarty.session.fg=='家长' }>欢迎你<{$smarty.session.user}>家长<{/if}>

2010-09-30 09:31:54

#6 xpp1000

可不可以在家smarty中直接写PHP代码

2010-09-30 10:34:51

#7 jake

可不可以在家smarty中直接写PHP代码
xpp1000 发表于 2010-9-30 10:34
在smarty模板中,可以用{include_php}标签来包含PHP代码文件。

http://www.smarty.net/manual/en/language.function.include.php.php

另外:{php}{/php}标签内可以写PHP代码,但{php}都受到$php_handling的影响,在SP中就是 $this->getView()->php_handling 的设置。

http://www.smarty.net/manual/en/variable.php.handling.php

2010-09-30 11:05:24