Mecha CMS

Mecha CMS blog and documentation.

Class Tree

Updated: Sunday, 07 August 2016

Convert array to list item.

Added since version 1.2.0.

Configuration

Tree::$config = array(
    'trunk' => 'ul',
    'branch' => 'ul',
    'twig' => 'li',
    'classes' => array(
        'trunk' => 'trunk',
        'branch' => 'branch branch-%d',
        'twig' => 'twig',
        'current' => 'current',
        'chink' => 'chink'
    )
);

Usage

Convert array to list item.

echo Tree::grow(array(
    'Example 1' => '/',
    'Example 2' => '/example',
    'Example 3' => '?example',
    'Example 4' => '#example',
    'Example 5' => 'javascript:void(0)',
    'Example 6' => array(
        'Example 6.1' => '/child-1',
        'Example 6.2' => '/child-2'
    ),
    'Example 7 (/parent)' => array(
        'Example 7.1' => '/parent/child-1',
        'Example 7.2' => '/parent/child-2'
    ),
    'Example 8',
    'Example 9' => null,
    'Example 10' => ""
));

Results:

<ul class="trunk">
  <li class="twig"><a href="https://mecha-cms.com/2016">Example 1</a></li>
  <li class="twig"><a href="https://mecha-cms.com/2016/example">Example 2</a></li>
  <li class="twig"><a href="?example">Example 3</a></li>
  <li class="twig"><a href="#example">Example 4</a></li>
  <li class="twig"><a href="javascript:void(0)">Example 5</a></li>
  <li class="twig ul">
    <span class="a">Example 6</span>
    <ul class="branch branch-1">
      <li class="twig"><a href="https://mecha-cms.com/2016/child-1">Example 6.1</a></li>
      <li class="twig"><a href="https://mecha-cms.com/2016/child-2">Example 6.2</a></li>
    </ul>
  </li>
  <li class="twig ul">
    <a href="https://mecha-cms.com/2016/parent">Example 7</a>
    <ul class="branch branch-1">
      <li class="twig"><a href="https://mecha-cms.com/2016/parent/child-1">Example 7.1</a></li>
      <li class="twig"><a href="https://mecha-cms.com/2016/parent/child-2">Example 7.2</a></li>
    </ul>
  </li>
  <li class="twig"><span class="a">Example 8</span></li>
  <li class="twig"><span class="a">Example 9</span></li>
  <li class="twig chink"></li>
</ul>

Hooks

Filter

FilterDescription
tree:trunkWill affect the generated tree trunk.
tree:branchWill affect the generated tree branch.
tree:twigWill affect the generated tree twig.
tree:urlWill affect the generated tree URL.
tree:anchorWill affect the generated tree anchor and span tag.
trunkWill affect the generated trunk.
branchWill affect the generated branch.
twigWill affect the generated twig.
urlWill affect the generated URL.
anchorWill affect the generated anchor and span tag.

Weapon

None.

Donation and Email Subscription