{recurse}

Inside a {tree}: renders the tree's body once more for the children of the current row.

Loops and trees Single tags

Syntax

{recurse}

Description

{recurse} is where the children of the current row go. It renders the body of the enclosing {tree} - the content as written between {tree} and {/tree} - again, once for every child, each child a row of its own with its own fields. Inside that body {recurse} works again one level down, so the tree is rendered to any depth. A row without children renders nothing here.

The new list is a level named as the tree is: depth@tree is one more than the level above, and first@tree, current@tree and count@tree speak of the children being rendered. The tree's sort, where and reverse options are carried along, so children are ordered and filtered as their parents were.

Usually it stands inside {branch}, so the list markup around it only appears for a row that has children. The tag takes no parameters; under the strict syntax check a {recurse} outside a tree is an error.

Examples

Threaded comments

Each reply is rendered by the same body one level deeper, indented by its depth.

Templateexamples/recurse/1-comments.pad
{data 'recurseThread'}
[
  { "who": "Ann", "text": "Is the shop open on Sunday?", "children": [
      { "who": "Ben", "text": "Only in December.", "children": [
          { "who": "Ann", "text": "Thanks!" } ] },
      { "who": "Cy", "text": "Check the calendar page." } ] },
  { "who": "Dee", "text": "Great service." }
]
{/data}
{tree 'recurseThread'}
  <p style="margin-left: {echo (depth@tree - 1) * 2}em"><strong>{$who}</strong>: {$text}</p>
  {recurse}
{/tree}
Resultopen alone

Ann: Is the shop open on Sunday?

Ben: Only in December.

Ann: Thanks!

Cy: Check the calendar page.

Dee: Great service.

Filtered at every depth

A where option on the tree is carried along by recurse - hidden rows are left out at every level.

Templateexamples/recurse/2-where.pad
{data 'recurseSite'}
[
  { "page": "About", "hidden": 0, "children": [
      { "page": "Team", "hidden": 0 },
      { "page": "Drafts", "hidden": 1 } ] },
  { "page": "Admin", "hidden": 1, "children": [ { "page": "Users", "hidden": 0 } ] },
  { "page": "Blog", "hidden": 0 }
]
{/data}
<ul>
{tree 'recurseSite', where='$hidden eq 0'}
  <li>{$page}{branch}<ul>{recurse}</ul>{/branch}</li>
{/tree}
</ul>
Resultopen alone
  • About
    • Blog

    See also

    • {tree} Renders a tree of rows: its body for every row, and {recurse} renders it again for the row's children.
    • {branch} Inside a {tree}: renders its content only when the current row has children, its @else@ part for a leaf.