{recurse}
Inside a {tree}: renders the tree's body once more for the children of the current row.
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.
{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}
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.
{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>
- About
- Blog