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.