The in tag and range tag of ThinkPHP template are used to determine whether a template 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>
When used, set variables in module operations (such as Index/display) and assign values to templates:
$groupId = 1; $this->assign( "groupId", $groupId );
Template/Tpl/default/Index/display.html, use the in tag as follows:
<in name="groupId" value="1,2,3">管理群组</in>
Run this example to output:
Manage Groups
The php code for this example is equivalent to:
<?php if(in_array(($groupId), explode(',',"1,2,3"))){ echo '管理群组'; } ?>
Note: The value of a variable can also be a string or an array, and the value of the value attribute can use a variable.
2.notin tag
Corresponding to the in tag is the notin tag, which means it is judged not to be within a certain range:
Usage such as:
<notin name="groupId" value="1,2,3">非管理群组</notin>
The above two tag examples combined are equivalent to:
<in name="groupId" value="1,2,3">管理群组<else />非管理群组</in>
3.range tag
ThinkPHP’s in and notin tags can also be replaced by range tags, such as:
<range name="groupId" value="1,2,3" type="in" >管理群组</range>
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.