thinkphp Template If label usage detailed _php example

Source: Internet
Author: User
Tags php template smarty template

The thinkphp if tag can be used to define complex conditional judgments , such as:

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

Note: in the condition attribute, you can support an EQ and other judgment expression, with the comparison label above, but it does not support the use of symbols with ">", "<", because it confuses template parsing , so the following usage is incorrect:

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

Must be changed to:

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

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

<if condition= "Strtoupper ($user [' name ']) neq ' thinkphp '" > thinkphp <else/> Other
Framework
</if>

The Condition property can support point syntax and object syntax, such as automatically determining whether the user variable is an array or an object:

<if condition= "$user. Name neq ' thinkphp '" > thinkphp <else/> Other
Framework
</if>

Or know that the user variable is an object

<if condition= "$user: Name Neq ' thinkphp '" > thinkphp <else/> Other
Framework
</if>

Note: because the condition property of the IF tag basically uses the PHP syntax, it is more concise to use the judgment tag and switch label as much as possible, and in principle, it can be solved with switch and comparison tags as far as possible without the IF tag. Because switch and comparison labels can use variable regulators and system variables. If some special requirements below, if tag still can't meet the requirements, you can use the native PHP code or PHP tag to write the code directly .

More interested in thinkphp related content readers can view the site topics: "thinkphp Introductory Course", "thinkphp Template Operation Skills Summary", "thinkphp Common Methods Summary", "Smarty Template Introductory Course" and "PHP template technology Summary."

I hope this article will help you with the PHP program design based on thinkphp framework.

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.