ThinkPHP Template Comparison Tag Usage Detailed Explanation

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

The ThinkPHP template engine provides a wealth of comparison tags, which are used in the following format:


< Compare labels  name=" Variable " value=" Value "> Content </ Compare labels >

The comparison tags supported by ThinkPHP system and their meanings are:

eq or equal: Equals
neq or notequal: Not equal to
gt: Greater than
egt: Greater than or equal to
lt: Less than
elt: Less than or equal to
heq: Constant equals
nheq: Inconstant equals

1. The usage of comparison labels is basically 1, and the difference lies in the different judgment conditions.

For example, eq label:


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

Indicates that the value of name variable is equal to value.

Or it can be written as:


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

It can also be mixed with else tags, such as:


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

The gt tag is used as follows:


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

Indicates that when the value of name variable is greater than 5, it will be output

The egt tag is used as follows:


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

It means that when the value of name variable is not less than 5, it will be output

2. Variables in comparison tags can support attributes or arrays of objects, or even system variables:

An example of the eq tag is as follows:


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

Indicates that when the vo object's attribute (or array, or automatic judgment) is equal to 5, it is output


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

Indicates that when the attribute of vo object is equal to 5, it is output


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

Indicates output when $vo ['name'] equals 5


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

Such as:


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

When the string length of the attribute value of vo object is equal to 5, it is output

4. Variable names can support system variables in ways such as:


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

5. Usually, the value of the comparison tag is a string or a number. If you need to use variables, you only need to add a "$" flag in front of it.

Such as:


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

Indicates that when the attribute of an vo object is equal to $a, it is output

6. All comparison tags can use compare tags (in fact, all comparison tags are aliases of compare tags), such as:


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

Indicates that when the value of name variable is equal to 5, it will be output

Equivalent to


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

Where the value of the type attribute is the comparison tag name listed above


Related articles: