<?php use Drupal\Core\Routing\RouteMatchInterface; function tsa2_theme($existing, $type, $theme, $path) { // return [ // 'tsa_template' => [ // 'variables' => ['source_text' => NULL], // ], // ]; $variables = array( 'tsa2_theme' => array( 'variables' => array( 'tsa2_api' => NULL, 'mainBody' => NULL, ), 'template' => 'tsa2-template', ), ); return $variables; } function tsa2_preprocess_html(&$variables) { $variables['#attached']['library'][] = 'tsa2/tsa2'; $config = \Drupal::config('tsa2.settings'); $tsa2_api = $config->get('tsa2_api'); $variables['#attached']['drupalSettings']['tsa2']['tsa2_api'] = $tsa2_api; }