| Recommend this page to a friend! |
| Packages of Rafa Rodriguez | Div PHP Template Engine | docs/Features/Conditions.md | Download |
|
|||||||||||||||||||||
The conditions is more complicated than conditional parts. With conditions, you can show conditional parts based on a boolean expression and not only from a boolean value. See the allowed PHP functions. The expression can be an expression of PHP, blended with code of Div. Syntax:
Example index.php
index.tpl
Output
You must understand that the expression in parentheses will be interpreted by the template engine as well. That means the end result of that interpretation must be a valid PHP boolean expression. An example to understand this is when comparing to strings.
Notice carefully how the $userRole variable substitution is enclosed in quotes.
This means that when it is substituted for its value, the value will be enclosed in quotes, because you have told the template engine so.
The following would be an error, because the content of the variable would not be enclosed in quotes and would not result in a valid expression for PHP.
Output:
|