Home >Backend Development >PHP Tutorial >ThinkPHP template judgment output Defined tag usage detailed explanation_PHP tutorial

ThinkPHP template judgment output Defined tag usage detailed explanation_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:26:19974browse

The defined tag of the ThinkPHP template engine is used to determine whether the constant has been defined .
ThinkPHP's defined tag is used to determine whether a constant has been defined. Its function is equivalent to the defined() function in PHP. The defined tag is used as follows:

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

First define a constant in the module operation (such as: Index/display) and output the template:

define("SITE_NAME", "脚本之家");
$this->display();

Use the defined tag in template/Tpl/default/Index/display.html as follows:

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

Running this example will output:

网站名称:脚本之家

The equivalent PHP code for this example is as follows:

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

If the judgment is not defined, you can use:

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

The above two examples are combined as follows:

<defined name="SITE_NAME">网站名称:{*SITE_NAME}<else/>{*SITE_NAME}不存在活未定义</defined>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/824720.htmlTechArticleThe defined tag of ThinkPHP template engine is used to determine whether the constant has been defined. ThinkPHP's defined tag is used to determine whether a constant has been defined. Its function is equivalent to defin in PHP...
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