with

An article by Gaspard Bucher

Replace a part of an included template.

  1. action
  2. ajax
  3. API
  4. classes
  5. common attributes
  6. conditions
  7. context
  8. dates
  9. display
  10. forms
  11. i18n
  12. meta
    1. debug
    2. default
    3. headers
    4. include
    5. not_found
    6. possible_roles
    7. roles
    8. with
  13. SQLiss
  14. urls

Replace a part of an included template.

  • part name of the part to modify
  • do method to use as replacement
see include, name
<r:include template='layout.html'>
  <r:with part='stylesheets'>
    <r:stylesheets list='reset,zena,code'/>
    <link href="super.css" rel="Stylesheet" type="text/css"/>
  </r:with>
  <r:with part='related'/>
  <r:with part='doc_list' do='documents'>
    <li do='each' do='link'/>
  </r:with>
</r:include>

This method is a very powerful way to specialize a template by modifying only the parts that need to be different, keeping the rest as it is.

If the with is an empty tag as in the second example above, the element is removed from the included template. In the example, related will be removed.

In the last example, we use the do syntax to replace the original method. For example, if the orginal code was:

<ul id='doc_list' do='pages'>
  ...
</ul>

or

<ul><r:pages name='doc_list'>
  ...
</ul>

After replacement from the last example above, we would get:

<ul id='doc_list' do='documents'>
  <li do='each' do='link'/>
</ul>

or

<ul><r:documents name='doc_list'>
  <li do='each' do='link'/>
</ul>

See name on how names are set.