To set conditions on data, if-statements can be used;
if-statement
{{$name = 'Andor'}}
{{if $name eq 'Fred'}}
Welcome Sir.
{{elseif $name eq 'Wilma'}}
Welcome Ma'am.
{{else}}
Welcome visitor.
{{/if}}
Output:
Welcome visitor
Below is an overview of the most commonly used conditions that can be set within an if statement;
Comparison | Condition | Textual alternative |
---|
equals | == | eq |
not equals | != | neq, ne |
less than | < | lt |
less than or equal | <= | lte, le |
greater than | > | gt |
greater than or equal | >= | gte, ge |
not | ! |
|
or | || | OR |
and | && | AND |
Textual condition
It is safer to use the textual variant in if-statements, as these will never be altered by the browser or WYSIWYG editor.
Multiple if-statements
{{$name = 'Andor'}}
{{$age = 33}}
{{if $name eq 'Fred' || $name eq 'Andor'}}
{{if $age gte 18}}
Welcome Sir.
{{else}}
Welcome Boy.
{{/if}}
{{elseif $name eq 'Wilma' || $name == 'Johanna'}}
{{if $age gte 18}}
Welcome Ma'am.
{{else}}
Welcome Girl.
{{/if}}
{{else}}
Welcome visitor.
{{/if}}
Output:
Welcome Sir.