If the above labels cannot meet the condition judgment requirements, we can also use the if label to define complex condition judgment.
If the above labels cannot meet the condition judgment requirements, we can also use the if label to define complex condition judgment.
If tag (condition-based tag) |
Close |
Non-closed labels |
Attribute |
Condition (required): condition to be judged |
Elseif tag) |
Close |
Close tags |
Attribute |
Condition (required): condition to be judged |
Else tag (conditional judgment tag) |
Close |
Close tags |
Attribute |
None |
Usage example:
- Value1
- Value2
- Value3
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:
- Value1
- Value2
Must be changed:
- Value1
- Value2
In addition, we can use php code in the condition attribute, for example:
- ThinkPHP
- Other Framework
The condition attribute supports dot syntax and object syntax, for example:
Automatically determines whether the user variable is an array or an object
- ThinkPHP
- Other Framework
Or you know that the user variable is an object.
- ThinkPHP
- Other Framework
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.