Detailed explanation of ThinkPHP template judgment output Defined tag usage

  • 2021-07-06 10:29:07
  • OfStack

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


<present name=" Constant "> What to Output </present>

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


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

The defined tag used in templates/Tpl/default/Index/display. html is as follows:


<defined name="SITE_NAME"> Website name: {*SITE_NAME}</defined>

Running the example outputs:


 Website Name: Script Home 

The equivalent php code for this example is as follows:


<?php
if(defined("SITE_NAME")){
  echo ' Website name: ',constant("SITE_NAME");
}
?>

If the judgment is not defined, you can use:


<notdefined name="SITE_NAME">{*SITE_NAME} There is no live undefined </notdefined>

The above two examples are combined as follows:


<defined name="SITE_NAME"> Website name: {*SITE_NAME}<else/>{*SITE_NAME} There is no live undefined </defined>

Related articles: