Вопрос

I have been trying to use different status message templates. But I do not know if we can use different status message templates for different pages. Is it possible?

Right now, I am using

status-messages.html.twig

Any help would highly be appreciated. Thanks!

Это было полезно?

Решение

Here is an example adding routename to status messages' templates suggestions (you may also add some parameters or whatever you need)

/**
 * Implements hook_theme_suggestions_HOOK_alter().
 */
function HOOK_theme_suggestions_status_messages_alter(array &$suggestions, array $variables) {
  $route = \Drupal::routeMatch();
  $suggestions[] = 'status_messages__'.str_replace('.','_', $route->getRouteName());
}

This way you can have status-messages--[routename].html.twig as a template, and if this file not exists, have a fallback to status-messages.html.twig

Лицензировано под: CC-BY-SA с атрибуция
Не связан с drupal.stackexchange
scroll top