ThinkPHP template IF tag Usage Details

Source: Internet
Author: User

The IF tag of ThinkPHP can beUsed to define complex condition judgmentsFor example:

<if condition="($name eq 1) OR ($name gt 100) "> value1<elseif condition="$name eq 2" />value2<else /> value3</if>

Note: The condition attribute supports 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:

<if condition="$id < 5 "> value1<else /> value2</if>

Must be changed:

<if condition="$id lt 5 "> value1<else /> value2</if>

In addition, wePhp code can be used in the condition attributeFor example:

<if condition="strtoupper($user['name']) neq 'THINKPHP' "> ThinkPHP<else /> other Framework</if>

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

<if condition="$user.name neq 'ThinkPHP' "> ThinkPHP<else /> other Framework</if>

Or you know that the user variable is an object.

<if condition="$user:name neq 'ThinkPHP' "> ThinkPHP<else /> other Framework</if>

Note: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 switch and comparison labels can use variable regulators and system variables. IF the IF tag still cannot meet the requirements under some special requirements, you can use native php code or PHP label to directly write the code..

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.