Home  >  Article  >  Backend Development  >  ThinkPHP模板判断输出Defined标签用法详解_PHP

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

WBOY
WBOYOriginal
2016-06-01 11:51:551113browse

ThinkPHP

ThinkPHP模板引擎的defined标签用于判断常量是否已经被定义
ThinkPHP的defined标签用来判断常量是否已经被定义,其功能相当于PHP中的defined()函数。defined标签用法如下:

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

先在模块操作(如:Index/display )里定义一个常量并输出模板:

define("SITE_NAME", "");
$this->display();

在模板/Tpl/default/Index/display.html中使用defined标签如下:

<defined name="SITE_NAME">网站名称:{*SITE_NAME}</defined>

运行该示例会输出:

网站名称:

该例子等价的php代码如下:

<&#63;php
if(defined("SITE_NAME")){
  echo '网站名称:',constant("SITE_NAME");
}
&#63;>

如果判断没有被定义,可以使用:

<notdefined name="SITE_NAME">{*SITE_NAME}不存在活未定义</notdefined>

以上两个示例合并之后如下:

<defined name="SITE_NAME">网站名称:{*SITE_NAME}<else/>{*SITE_NAME}不存在活未定义</defined>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn