ThinkPHP template range judgment output In tag and Range tag usage

不言
Release: 2023-03-30 09:46:01
Original
1937 people have browsed it

This article mainly introduces the usage of the In tag and the Range tag of the ThinkPHP template range judgment output. Friends who need it can refer to the

The in tag and range tag of the ThinkPHP template are used tojudge a certain template. Whether the variable is within a certain range.
1.in tag
ThinkPHP’s in tag is used to determine whether a template variable is within a certain range. The format is as follows:

<in name="变量名" value="值1,值2,...">要输出的内容</in>
Copy after login

When used, in the module Set variables in operations (such as Index/display) and assign values ​​to the template:

$groupId = 1;
$this->assign( "groupId", $groupId );
Copy after login

Template/Tpl/default/Index/display.html, use the in tag as follows:

<in name="groupId" value="1,2,3">管理群组</in>
Copy after login

Run the Example, can output:

Management Group

The php code of this example is equivalent to:

<?php
if(in_array(($groupId), explode(&#39;,&#39;,"1,2,3"))){
  echo &#39;管理群组&#39;;
}
?>
Copy after login

Note: The value of the variable can also be a string or array , the value of the value attribute can use variables.

2.notin tag

There is also a notin tag corresponding to the in tag, which means it is judged not to be within a certain range:
Usage such as:

<notin name="groupId" value="1,2,3">非管理群组</notin>
Copy after login

The above two tag examples combined are equivalent to:

<in name="groupId" value="1,2,3">管理群组<else />非管理群组</in>
Copy after login

3.range tag

ThinkPHP’s in and notin tags can also be used range tag instead, such as:

<range name="groupId" value="1,2,3" type="in" >管理群组</range>
Copy after login

The above example is equivalent to the in tag. When the value of the type attribute is notin, it is equivalent to the notin tag.

Related recommendations:

How to use thinkPHP’s Html template tag

ThinkPHP template judgment output Empty tag usage

The above is the detailed content of ThinkPHP template range judgment output In tag and Range tag usage. For more information, please follow other related articles on the PHP Chinese website!

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