Home >Backend Development >PHP Tutorial >ThinkPHP template judgment output Defined tag usage detailed explanation_PHP tutorial
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:
<?php if(defined("SITE_NAME")){ echo '网站名称:',constant("SITE_NAME"); } ?>
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>