0

I need the different html template for one my custom page. So I try suggestions hook alter, but it's don't work.

/**
 * Implements hook_theme_suggestions_HOOK_alter().
 */
function mymodule_search_theme_suggestions_html_alter(array &$suggestions, array $variables) {
  $current_path = \Drupal::service('path.current')->getPath();
  if ($current_path == '/map') {
    $suggestions[] = 'html__map';
  }
}

Template file I put in

mymodule/templates/html--map.html.twig

How I can override html template for my custom page?

2

You've almost done it but $current_path = \Drupal::service('path.current')->getPath(); return real path, not the alias , you should get its path alias

/**
 * Implements hook_theme_suggestions_HOOK_alter().
 */
function mymodule_search_theme_suggestions_html_alter(array &$suggestions, array $variables) {

  $current_path = \Drupal::service('path.current')->getPath();
  $result = \Drupal::service('path.alias_manager')->getAliasByPath($current_path);
  if ($result == '/map') {
    $suggestions[] = 'html__map';
  }
}

don't forget to clear the cache after that.

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.