PHP Smarty character comparison code

  • 2020-03-31 21:35:59
  • OfStack

Eq is equal,
Ne and neq are not equal,
Gt is greater than,
Lt is less than,
Gte and ge are greater than or equal to,
Lte, le is less than or equal to,
Not not mod.
Is [not] div by divisible by something,
Is [not] even even,
$a is [not] even by $b = ($a / $b) % 2 == 0,
Is [not] odd
$a is not odd by $b = ($a / $b) % 2 factorial. = 0 example:
Equal/not equal/ greater than/ less than/ less than/ less than or equal/ great than or equal/ not equal
The if statement in Smarty is as flexible and easy to use as the if statement in PHP, and several features have been added to suit the templating engine. 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, ==,! =, > , < , < =, > =. These modifiers must be separated from variables or constants by Spaces.

Example 7 to 11. The if statements
Example 7-11. If statement

{if $name eq "Fred"}
Welcome, Sir.
{elseif $name eq "Wilma}"
Welcome Ma '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
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 calls *}
{if the 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. for,
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}

Related articles: