else

An article by Gaspard Bucher

else clause in conditional context

  1. action
  2. ajax
  3. API
  4. classes
  5. common attributes
  6. conditions
    1. blank?
    2. case
    3. ClassCondition
    4. else
    5. if
    6. is_ancestor?
    7. selenium
    8. when
  7. context
  8. dates
  9. display
  10. forms
  11. i18n
  12. meta
  13. SQLiss
  14. urls

else clause in conditional context

  • eval evaluate a RubyLess expression
  • text, t RubyLess evaluated string.
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)'/>