thinkphp Template Comparison Label usage detailed _php example

Source: Internet
Author: User
Tags constant

The thinkphp template engine provides a rich comparison label in the format of:

< comparison label name= "variable" value= "value" > Content </Comparison label >

The comparison label supported by the thinkphp system and the meanings it represents are:

EQ or equal: equal to
NEQ or notequal: Not equal to
GT: Greater Than
EGT: greater than or equal
LT: less than
ELT: less than or equal
Heq: Constant equals
Nheq: not constant equals

1. The usage of the comparison label is basically consistent, the difference being that the condition of judgment is different .

such as EQ Label:

<eq name= "name" value= "value" >value</eq>

Indicates that the value of the name variable equals value is output.

Or it can be written as:

<equal name= "name" value= "value" >value</equal>

You can also support the mixed use of the else tag , such as:

<eq name= "name" value= "value" > Equality <else/> inequality </eq>

The GT tag is used as follows:

<GT name= "Name" value= "5" >value</gt>

Represents the output when the value of the name variable is greater than 5

The EGT label is used as follows:

<egt name= "Name" value= "5" >value</egt>

Indicates that the value of the name variable is output when it is not less than 5

2. Comparisons of variables in a label can support an object's properties or an array, or even a system variable :

The EQ tag example is as follows:

<eq name= "Vo.name" value= "5" >{$vo .name}</eq>

Represents the output when a Vo object's attributes (or an array, or automatic judgment) equals 5

<eq name= "Vo:name" value= "5" >{$vo .name}</eq>

Represents the output when a Vo object's property equals 5

<eq name= "vo[' name '" "value=" 5 ">{$vo .name}</eq>

Indicates that when $vo[' name ' equals 5, the output


3. You can also support the use of functions on variables

Such as:

<eq name= "Vo:name|strlen" value= "5" >{$vo .name}</eq>

Indicates that the string length of the attribute value of the Vo object is equal to 5.

4. Variable names can support the way system variables , for example:

<eq name= "Think.get.name" value= "value" > Equality <else/> inequality </eq>

5. Usually the value of the comparison label is a string or a number, and if you need to use a variable, simply add the "$" flag to the front .

Such as:

<eq name= "Vo:name" value= "$a" >{$vo .name}</eq>

Represents the output when a Vo object's attributes are equal to $a

6. All comparison tags can be uniformly used compare tags (in fact all of the comparison tags are compare tags alias), for example:

<compare name= "Name" value= "5" type= "EQ" >value</compare>

Represents the output when the value of the name variable equals 5

is equivalent to

<eq name= "Name" value= "5" >value</eq>

The value of the Type property is the comparison label name listed above

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: info-contact@alibabacloud.com 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.