Use the judgment statement in the ThinkPHP Template

Source: Internet
Author: User
We can use the if tag to define complex condition judgments, such as: & lt; ifcondition & quot; ($ nameeq1) OR ($ namegt100) & quot; & gt; value1 & lt; elseifcondition & quot; $ nameeq2 & quot;/& gt; value2 & lt; else...

We can use the if tag to define complex condition judgments, for example:

  1. Value1
  2. Value2
  3. Value3
  4.  

In the condition attribute, you can support eq and other judgment expressions. comparison labels are the same as above, but they do not support the use of symbols such as ">" and "<", because template parsing is obfuscated, so the following usage is incorrect:

  1. Value1
  2. Value2
  3.  

Must be changed:

  1. Value1
  2. Value2
  3.  

In addition, we can use php code in the condition attribute, for example:

  1. ThinkPHP
  2. Other Framework
  3.  

The condition attribute supports dot syntax and object syntax. for example, it automatically determines whether the user variable is an array or an object:

  1. ThinkPHP
  2. Other Framework
  3.  

Or you know that the user variable is an object.

  1. ThinkPHP
  2. Other Framework
  3.  

Because the condition attribute of the if tag basically uses the php syntax, it is more concise to use the judgment tag and Switch tag. in principle, if you can use the switch or comparison label, try not to use the if label, because the switch and comparison label can use the variable regulator and system variable. if there are some special requirements, IF the label still cannot meet the requirements, you can use the native php code or PHP label to directly write the code.

Eq equals (=)

Neq is not equal (! =)

Gt greater than (>)

Egt greater than or equal to (> =)

Lt is less than (<)

Elt less than or equal to (<=)

Heq constant equals (=)

Nheq is not always equal (! =)

Condition

Note:In the condition attribute value, the variable requires the $ symbol, which is different from other labels.

Tip:In judging the output series labels, use more concise comparison labels and switch labels as much as possible.

If the judgment labels provided by ThinkPHP still cannot meet special requirements, you can directly use native PHP code or PHP labels to meet the requirements.

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.