else clause in conditional context |
|
| see eval, if, text, t, unknown, zena 1.0 | |
Conditional block execution.
<r:if test='visitor.is_admin?'> do something <r:else> do something else </r:else> </r:if>
All contexts that can potentially return nil are treated as “if” clauses:
<r:to_publish> some articles are waiting for publication <r:else> nothing to publish </r:else> </r:to_publish>
Or
<r:hot> <r:text/> <!-- show hot text --> <r:else> <r:text/> <!-- show current text --> </r:else> </r:hot>
shortcuts
Sometimes we just need to write a message or execute a method. In this case we should use the “do” syntax:
<r:else do='text'/> or <r:else do='t' text='nothing to publish'/>
html attributes
You can overwrite html attributes from the main if tag in the else clause:
<div do='if' test='name'> I have a name <r:else class='error'> I do not have a name ! </r:else> </div>
On a node with an empty ‘name’ attribute, this will produce:
<div class='error'>I do not have a name !</div>
tricks with context
See the else clause of context for tricks with the “else” clause:
<r:hot else='self' do='zazen(text)'/>