conditional execution |
|
| see ..._if, case, ClassCondition, else, when, zena 1.0 | |
Conditional execution can be used to display content depending on user rights or other conditions:
<r:if test='can_edit?'> <r:link mode='edit'>clic to edit</r:link> </r:if>
When the test cannot be confused with a regular method, the code above can be written more shortly without the “if” or with a “do” method:
<r:can_edit?> <r:link mode='edit'>clic to edit</r:link> </r:can_edit?> <div do='can_edit?'> <r:link mode='edit'>clic to edit</r:link> </div>
If you want to use > or < in tests, you need to escape them with > and < respectively:
<r:if test='created_at > date'>
workflow conditions
Available conditions related to user rights:
can_edit? can_write? can_drive? public? empty?
conditional contexts / class scopes
Any context and ClassCondition behave like an “if” conditional execution:
<div do='pages' limit='1'> ... has pages ... <r:else> does not have pages </r:else> </div>
Note that you should limit the query to a single object if you just want to test for page existence.
Or
<div do='Image'> ... I am an image ... <r:else> I am not an image </r:else> </div>
ancestor tag
You can use in to test wether the current element is inside a given ancestor method:
<r:if in='form'>we are in a form</r:if>