context

An article by Gaspard Bucher

Enter a new context.

  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

Enter a new context.

see find, unknown
<r:context find='all' select='pages where name like "b%" in site'/>
  ...
</r:context>

pseudo sql

The “select” argument should contain SQLiss code, either complete with all arguments:

<r:context select='images where updated_at gt now - 2 days in site'>
  ...
</r:context>

Or with arguments in separate attributes:

<r:context select='images' where='updated_at gt now - 2 days' in='site'>
  ...
</r:images>

Finally, it is better style to use unknown resolution instead of the “context” tag (but this is not always possible if you have a name clash with zafu tags or RubyLess methods):

<r:images where='updated_at gt now - 2 days' in='site'>
  ...
</r:images>

Same with an html tag and the “do” syntax:

<ul do='images' where='updated_at gt now - 2 days' in='site'>
  ...
</ul>

tag rendering

If the new context is empty, the tag is not rendered unless it contains an add method and the visitor has write access to the new context.

<ul do='references'>...</ul>

In the example above, if ‘references’ is empty, the ul tag will not be present in the rendered page.

ajax pagination

An ajax pagination lets you update only a specific block (id pagir in this example) when the user presses on “previous” or “next”.

<div id='pagir' do='block'>
  <ul do='images' in='site' order='created_at desc' limit='8' paginate='foo'>
    <li><b do='[foo_nodes]'/> nodes</li>
    <li>
      <r:link update='pagir' page='previous' do='t'>previous</r:link>
      <r:show var='foo'/>/<r:show var='foo_count'/>
      <r:link update='pagir' page='next' do='t'>next</r:link>
    </li>
    <li do='each' do='link' do='img'/>
  </ul>
</div>

Note the special variables “foo_count”, “foo_nodes” and “foo” named after the paginate key. These variables have the following meaning:

  • foo_count page count
  • foo_nodes number of nodes
  • foo current page number

The page size is defined by the limit clause in the pseudo sql finder (8 in our example).

Else clause

You can use “else” to set default contexts such as:

<div do='recipient' else='contact in project'>
  <!-- defined recipient or default contact -->
</div>

This is not the same as an “or” clause in a query such as recipient or contact in project because of ordering issues.