Detailed explanation of ThinkPHP template judgment output Present tag usage

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

The present tag of the ThinkPHP template is used to determine whether a template variable has been assigned.

The present tag of the ThinkPHP template engine is used to determine whether the template variable has been assigned, and its function is equivalent to the isset () function behavior in PHP, and its format is as follows:


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

Examples of usage are as follows:


<present name="username">{$username}  Hello! </present>

This example is equivalent to:


if(isset($username)){
  echo "$username  Hello! ";
}

In addition, the notpresent tag can be used to judge that there is no assignment, and its usage is as follows:


<notpresent name="username">username There is no live unlogged </notpresent>

You can also merge the above two tags into:


<present name="username">{$username}  Hello! <else/>username There is no live unlogged </present>

Related articles: