You are here

toc-tree.html.twig in TOC API 8

Default theme implementation to display a Table of contents as a tree.

Returns HTML for a nested list representation of a Table of contents..

Available variables:

  • tree: A nested list of header items. Each header item contains:

    • list_tag: HTML tag for the list.
    • list_attributes: HTML attributes for the list.
    • attributes: HTML attributes for the table of contents or list item.
    • below: The table of contents child items.
    • title: The table of contents or header title.
    • url: The header fragrment (ie hash) URL, instance of \Drupal\Core\Url.

File

templates/toc-tree.html.twig
View source
  1. {#
  2. /**
  3. * @file
  4. * Default theme implementation to display a Table of contents as a tree.
  5. *
  6. * Returns HTML for a nested list representation of a Table of contents..
  7. *
  8. * Available variables:
  9. * - tree: A nested list of header items. Each header item contains:
  10. * - list_tag: HTML tag for the list.
  11. * - list_attributes: HTML attributes for the list.
  12. * - attributes: HTML attributes for the table of contents or list item.
  13. * - below: The table of contents child items.
  14. * - title: The table of contents or header title.
  15. * - url: The header fragrment (ie hash) URL, instance of \Drupal\Core\Url.
  16. *
  17. * @ingroup themeable
  18. */
  19. #}
  20. {#
  21. We call a macro which calls itself to render the full tree.
  22. @see http://twig.sensiolabs.org/doc/tags/macro.html
  23. #}
  24. {% import _self as toc_api_tree %}
  25. {% set classes = ['toc', 'toc-tree'] %}
  26. <div{{ attributes.addClass(classes) }}>
  27. {% if tree.title and not options.block %}
  28. <h3>{{ tree.title }}</h3>
  29. {% endif %}
  30. {{ toc_api_tree.tree_links(tree) }}
  31. </div>
  32. {% macro tree_links(item) %}
  33. {% import _self as toc_api_tree %}
  34. {% if item.below_type %}
  35. <ol class="{{ item.below_type }}">
  36. {% else %}
  37. <ul>
  38. {% endif %}
  39. {% for child_item in item.below %}
  40. <li{{ child_item.attributes.setAttribute('value', child_item.value) }}>
  41. {{ link(child_item.html, child_item.url) }}
  42. {% if child_item.below %}
  43. {{ toc_api_tree.tree_links(child_item) }}
  44. {% endif %}
  45. </li>
  46. {% endfor %}
  47. {% if item.below_type %}
  48. </ol>
  49. {% else %}
  50. </ul>
  51. {% endif %}
  52. {% endmacro %}