each

An article by Gaspard Bucher

loop through the elements of the current list

  1. action
  2. ajax
  3. API
  4. classes
  5. common attributes
  6. conditions
  7. context
    1. ancestors
    2. author
    3. comments
    4. comments_to_publish
    5. content_for_layout
    6. context
    7. count
    8. data
    9. each
    10. each_group
    11. expand_with
    12. find
    13. group
    14. node
    15. project
    16. proposed
    17. query
    18. query_errors
    19. query_parse
    20. real_project
    21. real_section
    22. redactions
    23. replies
    24. search_results
    25. section
    26. tags
    27. to_publish
    28. unknown
    29. user
    30. visitor
    31. visitor_node
  8. dates
  9. display
  10. forms
  11. i18n
  12. meta
  13. SQLiss
  14. urls

loop through the elements of the current list

  • join text to join elements together
  • draggable [true]
  • drag_handle (true|className)
  • alt_class class added to even rows
  • alt_reverse [true] start counting even/odd from end of list
see add, draggable, drop, each_group, edit, form, zena 1.0

Display

Display a list of links separated by a comma:

<ul do='projects'><li do='each' join=', '><r:link/></li>

Display a list of comments with stripes (alternating class):

<ul do='comments'>
  <li do='each' class='comment' alt_class='stripe' do='zazen' attr='text'>sample comment text</li>
</ul>

<!-- or you can use the 'alt_class' string if you need to use the class in more then one place -->
<r:each alt_class='foo'>
  <tr class='#{alt_class}'><td rowspan='2' do='title'/>...</tr>
  <tr class='#{alt_class}'>...</tr>
</r:each>

The example above will generate html code such as this:

<ul>
  <li class='comment'>...</li>
  <li class='comment stripe'>...</li>
  <li class='comment'>...</li>
  ...
</ul>

If your list fills on top (last element on top), you should use alt_reverse='true' so that inserting new elements does not change the stripes of the existing elements.

Documentation to rewrite

<ul do='notes'>
  <li do='each' draggable='true' do='link'/>
  <li do='add'/>
</ul>

This method also constructs the form needed to edit the elements of the list if the list contains an edit or an add but no form as in the last example above.

If you set draggable to “true”, the element can be used with drop. It is usually better to use a drag handle instead of the whole element or your users will have troubles clicking links. To do so, simply add drag_handle='true' and zena will insert a span at the start of the element. You can also insert your own element (default class is ‘drag_handle’).

You have to escape html in the join parameter by using &lt; and &gt;.

The “stripe” example above will give the following html:

<li class='note'>...</li>
<li class='note stripe'>...</li>