Fork me on GitHub


An article by Gaspard Bucher

Enter a new context.

Enter a new context.

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

pseudo sql (sqliss)

Note, that 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).

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'>

Or with arguments in separate attributes:

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

However, here it is better style to use unknown resolution:

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

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

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

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' find='first'>...</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>
      <r:link update='pagir' page='previous' do='t'>previous</r:link>
      <r:show eval='foo'/>/<r:show var='foo_count'/>
      <r:link update='pagir' page='next' do='t'>next</r:link>
    <li do='each' do='link' do='img'/>

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 -->

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