当前位置:首页 > PHP教程 > PHP常见问题

ThinkPHP模板判断输出Present标签用法详解

thinkphp模板的present标签用于判断模板变量是否已经赋值。

thinkphp模板引擎的present标签用来判断模板变量是否已经赋值,其功能相当于php中的isset()函数行为,格式如下:

<present name="变量名">要输出的内容</present>

用法举例如下:

<present name="username">{$username} 你好!</present>

该例子等同于:

if(isset($username)){ echo "$username 你好!"; }

此外,判断没有赋值可采用notpresent标签,用法如下:

<notpresent name="username">username不存在活未登录</notpresent>

还可以把上述两个标签合并为:

<present name="username">{$username} 你好!<else/>username不存在活未登录</present>


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:)!