ThinkPHP Template Range Judgment Output In Tag and Range Tag Usage Detailed Explanation

  • 2021-07-06 10:28:37
  • OfStack

The in tag and range tag of the ThinkPHP template are used to determine 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 range, using the following format:


<in name=" Variable name " value=" Value 1, Value 2,..."> What to Output </in>

When used, set variables in module operations (such as Index/display) and assign them 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"> Manage Groups </in>

Run the example to output:

Manage Groups

The php code for this example is equivalent to:


<?php
if(in_array(($groupId), explode(',',"1,2,3"))){
  echo ' Manage Groups ';
}
?>

Note: The value of a variable can also be a string or an array, and the value of the value property can use a variable.

2. notin tag

There is also an notin tag corresponding to the in tag, that is, the judgment is not within a certain range:
Usage such as:


<notin name="groupId" value="1,2,3"> Non-administrative group </notin>

The combination of the above two tag examples is equivalent to:


<in name="groupId" value="1,2,3"> Manage Groups <else /> Non-administrative group </in>

3. range tag

range and notin tags of ThinkPHP can also be replaced by range tags, such as:


<range name="groupId" value="1,2,3" type="in" > Manage Groups </range>

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


Related articles: