This article mainly introduces the usage of the output In tag and Range tag in the ThinkPHP template range judgment. For more information, see the In tag and Range tag in the ThinkPHP template.
Determines whether a template variable is within a certain range..
1. in tag
The in tag of ThinkPHP is used to determine whether a template variable is within a certain range. The format is as follows:
Content to be output
During use, set variables in module operations (such as Index/display) and assign values to the template:
$groupId = 1;$this->assign( "groupId", $groupId );
The template/Tpl/default/Index/display.html uses the in tag as follows:
Manage groups
Run this example and output:
Manage groups
The php code in this example is equivalent:
<? Phpif (in_array ($ groupId), explode (',', "1, 2, 3") {echo 'Manage group';}?>
Note: The value of a variable can also be a string or an array. The value attribute value can be a variable.
2. notin tag
There is also a notin tag corresponding to the in tag, that is, the judgment is not in a certain range:
Usage example:
Non-Management Group
The preceding two tag examples are equivalent:
Manage groups
Non-Management Group
3. range label
The in and notin labels of ThinkPHP can also be replaced by the range label, for example:
Manage groups
The preceding example is equivalent to the in tag. When the value of the type attribute is notin, it is equivalent to the notin tag.