You are here

function template_preprocess_toc_responsive in TOC API 8

Prepares variables for a responsive table of contents.

Default template: toc-responsive.html.twig.

Parameters

array $variables: An associative array containing the following keys:

  • toc: A TOC (table of contents) object.
  • attributes: Attributes to be added to back to top link.

File

./toc_api.module, line 174
Converts header tags into a hierarchical table of contents.

Code

function template_preprocess_toc_responsive(&$variables) {
  $variables['attributes'] = new Attribute($variables['attributes']);
  $variables['desktop'] = [
    '#theme' => 'toc_tree',
    '#toc' => $variables['toc'],
    '#attributes' => [
      'class' => 'toc-desktop',
    ],
  ];
  $variables['mobile'] = [
    '#theme' => 'toc_menu',
    '#toc' => $variables['toc'],
    '#attributes' => [
      'class' => 'toc-mobile',
    ],
  ];
  $variables['#attached']['library'][] = 'toc_api/toc.responsive';
}