Usage of the output In tag and Range tag In the ThinkPHP template Range judgment

Source: Internet
Author: User

The in label and range label of the ThinkPHP template are usedDetermines 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:

<In name = "variable name" value = "value 1, value 2,..."> content to be output </in>

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:

<In name = "groupId" value = "1, 2, 3"> Manage groups </in>

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:

<Notin name = "groupId" value = "1, 2, 3"> non-managed groups </notin>

The preceding two tag examples are equivalent:

<In name = "groupId" value = ", 3"> Manage groups <else/> unmanaged groups </in>

3. range label

The in and notin labels of ThinkPHP can also be replaced by the range label, for example:

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

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.