if, elseif, if

if statments give you a lot of functionality when it comes to customizing your layouts. Pair with some PieCMS Variables you can achieve any design you are after.

If statments look like this:

{if $page eq 'home'}
I am the home page
{elseif $page eq 'services'}
I am the services page
{else}
I am not the home or services page
{/if}

While the syntax is pretty standard of many other languages, the qualifer is a bit different. Below is a table that matches common qualifiers to the Smarty counterpart.

Qualifier Common Meaning Example
eq == equals $a eq $b
ne, neq != not equals $a neq $b
gt > greater than $a gt $b
lt < less than $a lt $b
gte, ge >= greater than or equal $a ge $b
lte, le <= less than or equal $a le $b

Examples

{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}

{* parenthesis are allowed *}
{if ( $amount < 0 or $amount > 1000 ) and $volume >= #minVolAmt#}
   ...
{/if}

{* you can also embed php function calls *}
{if count($var) gt 0}
   ...
{/if}

{* check for array. *}
{if is_array($foo) }
   .....
{/if}

{* check for not null. *}
{if isset($foo) }
   .....
{/if}

{* test if values are even or odd *}
{if $var is even}
   ...
{/if}
{if $var is odd}
   ...
{/if}
{if $var is not odd}
   ...
{/if}