{branch}

Inside a {tree}: renders its content only when the current row has children, its @else@ part for a leaf.

Loops and trees Tag pairs

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.

Templateexamples/branch/1-icons.pad
{data 'branchFiles'}
[
  { "name": "photos", "children": [
      { "name": "2026", "children": [ { "name": "harbour.jpg" } ] },
      { "name": "cat.jpg" } ] },
  { "name": "notes.txt" }
]
{/data}
<ul>
{tree 'branchFiles'}
  <li>{branch}&#128193; {$name}<ul>{recurse}</ul>@else@&#128196; {$name}{/branch}</li>
{/tree}
</ul>
Resultopen alone
  • ๐Ÿ“ photos
    • ๐Ÿ“ 2026
      • ๐Ÿ“„ harbour.jpg
    • ๐Ÿ“„ cat.jpg
  • ๐Ÿ“„ notes.txt

See also

  • {tree} Renders a tree of rows: its body for every row, and {recurse} renders it again for the row's children.
  • {recurse} Inside a {tree}: renders the tree's body once more for the children of the current row.