Comparison operators are often used in smarty. smarty has its own rules. smarty often uses comparison operators, and smarty has its own rules.
Eq equals,
Ne and neq are not equal,
Gt>,
Lt is less,
Gte and ge are greater than or equal,
Less than or equal to lte and le,
Not Non. mod modulo.
Is [not] can div by be divisible by a certain number,
, B z m e m I w0 is [not] Whether the even is an even number,
$ A is [not] even by $ B ($ a/$ B) % 2 = 0,
Is [not] is odd? P
$ A is not odd by $ B ($ a/$ B) % 2! = 0 example:
Equal/not equal/greater than/less than or equal/great than or equal/is not required.
The if statement in Smarty is as flexible and easy to use as the if statement in php, and several features are added to fit the template engine. if must appear in pairs with/if. else and elseif clauses can be used. you can use the following conditional modifiers: eq, ne, neq, gt, lt, lte, le, gte, ge, is even, is odd, is not even, is not odd, not, mod, div by, even by, odd by, = ,! =,>, <, <=,> =. When using these modifiers, it must be opened with an empty lattice with variables or constants.
Example 7-11. if statements
Example:
{If $ name eq "Fred "}
Welcome Sir.
{Elseif $ name eq "Wilma "}
Welcome m'am.
{Else}
Welcome, whatever you are.
{/If}
{* An example with "or" logic *}
{If $ name eq "Fred" or $ name eq "Wilma "}
...
{/If}
{* Same as above *}
{If $ name = "Fred" | $ name = "Wilma "}
...
{/If}
{* The following syntax will NOT work, conditional qualifiers
Must be separated from surrounding elements by spaces *}
{If $ name = "Fred" | $ name = "Wilma "}
...
{/If}
{* Parenthesis are allowed *}
{If ($ amount <0 or $ amount> 1000) and $ volume >=# minVolAmt #}
...
{/If}
{* You can also embed php function CILS *}
{If count ($ var) gt 0}
...
{/If}
{* Test if values are even or odd *}
{If $ var is even}
...
{/If}
{If $ var is odd}
...
{/If}
{If $ var is not odd}
...
{/If}
{* Test if var is divisible by 4 *}
{If $ var is div by 4}
...
{/If}
{* Test if var is even, grouped by two. I. e .,
0 = even, 1 = even, 2 = odd, 3 = odd, 4 = even, 5 = even, etc .*}
{If $ var is even by 2}
...
{/If}
{* 0 = even, 1 = even, 2 = even, 3 = odd, 4 = odd, 5 = odd, etc .*}
{If $ var is even by 3}
...
{/If}
Note: {**} is the note of smarty.
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