/** * Render a nested list of elements as HTML list item. The function calls itself in case * of nested elements (identified by the key 'nested'). * @param array $elements * @param Aura\View\View $context */ function renderTocList(array $elements, Aura\View\View $context) { foreach ($elements as $entry) { $entryObj = new Bookdown\Bookdown\Content\Heading($entry['number'], $entry['title'], $entry['href'], $entry['id']); echo '<li class="list-group-item">'; echo '<div class="row clearfix">'; echo '<div class="col-sm-2">' . '<span class="text-number">' . "{$entryObj->getNumber()}" . '</span></div>'; echo '<div class="col-sm-10">' . $context->anchorRaw($entryObj->getHref(), $entryObj->getTitle()) . '</div>'; echo '</div>'; if (isset($entry['nested'])) { $collapseId = 'collapse-' . $entryObj->getAnchor(); echo '<a class="bbt-toc-toggle badge glyphicon collapsed" href="#' . $collapseId . '" data-toggle="collapse" aria-expanded="false" aria-controls="' . $collapseId . '"></a>'; echo '<ul class="list-group list-toc-nested collapse" id="' . $collapseId . '">'; renderTocList($entry['nested'], $context); echo '</ul>'; } echo '</li>'; } }
* tobiju * * @link https://github.com/tobiju/bookdown-bootswatch-templates for the canonical source repository * @copyright Copyright (c) 2015 Tobias Jüschke * @license https://github.com/tobiju/bookdown-bootswatch-templates/blob/master/LICENSE.txt New BSD License */ if (!$this->page->hasTocEntries()) { return; } /** * Define on which level a collapsible sublist will be created. * @var integer */ $sublistLevelThrottle = getenv('TOC_SUBLIST_LEVEL') ?: 3; // We need to define functions in a separate file because Bookdown includes // this file multiple times. include_once __DIR__ . '/helper.inc'; ?> <h1><?php echo $this->page->getNumberAndTitle(); ?> </h1> <ul class="bbt-toc list-group"> <?php $entries = $this->page->getTocEntries(); $nestedEntries = tocEntriestoNestedList($entries, $sublistLevelThrottle); renderTocList($nestedEntries, $this); ?> </ul>