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?

closed as too broad by kiamlaluno Apr 7 at 19:16

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

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.

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