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
Release: 2016-07-13 10:26:19
Original
963 people have browsed it

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>
Copy after login

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

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

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

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

Running this example will output:

网站名称:脚本之家
Copy after login

The equivalent PHP code for this example is as follows:

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

If the judgment is not defined, you can use:

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

The above two examples are combined as follows:

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

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...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template