{branch}
Inside a {tree}: renders its content only when the current row has children, its @else@ part for a leaf.
Syntax
{branch} ... {recurse} ... {/branch}
{branch} ... @else@ ... {/branch}
Description
{branch} ... {/branch} is a condition for the body of a {tree}: its content renders when the current row of the tree has children, and is skipped when the row is a leaf. Its usual content is the list markup around a {recurse} - {branch}<ul>{recurse}</ul>{/branch} - so a leaf does not get an empty <ul></ul>.
An @else@ part renders for a leaf instead: a different icon, a link where a folder gets a toggle. The children are read from the field the tree's children= option names (children by default); a field that is missing or empty means no children.
The tag takes no parameters. It belongs inside a tree: under the strict syntax check a {branch} with no {tree} around it, or without its closing tag, is an error.
Examples
Folders and files
A row with children gets a folder and its list; a leaf gets the @else@ part.
{data 'branchFiles'}
[
{ "name": "photos", "children": [
{ "name": "2026", "children": [ { "name": "harbour.jpg" } ] },
{ "name": "cat.jpg" } ] },
{ "name": "notes.txt" }
]
{/data}
<ul>
{tree 'branchFiles'}
<li>{branch}📁 {$name}<ul>{recurse}</ul>@else@📄 {$name}{/branch}</li>
{/tree}
</ul>
- ๐ photos
- ๐ 2026
- ๐ harbour.jpg
- ๐ cat.jpg
- ๐ 2026
- ๐ notes.txt