0

I am overriding twig suggestions for node, but it sometimes happen and sometimes not, I have added this code in my .theme file.

```

function mediumish_blog_theme_suggestions_node_alter(array &$suggestions, array $variables) {

  $route_name = \Drupal::routeMatch()->getRouteName();
  if ($route_name == "entity.taxonomy_term.canonical" && $tid = \Drupal::routeMatch()->getRawParameter('taxonomy_term')) {
    $suggestions[] = 'node__view__taxonomy_term';
  } elseif (preg_match("/^view.archive.*$/", $route_name)) {
    $parameter = \Drupal::routeMatch()->getRawParameter('arg_0');
    if ($parameter != null) {
      $suggestions[] = 'node__view__archive_month';
    }
  }
}

```

5
  • And the suggestions are what, listed in the html source?
    – Kevin
    Apr 14, 2018 at 16:20
  • They are default ones.. like node--view--frontend.html.twig, * node--22--teaser.html.twig, node--22.html.twig, node--blog--teaser.html.twig, node--blog.html.twig, node--teaser.html.twig, node.html.twig
    – Ankit Jain
    Apr 14, 2018 at 18:56
  • I don't understand the $tid = \Drupal::routeMatch()->... part in your code, are you sure you want to use the assignment operator in your if-statement? The $tid variable isn't used anywhere. Maybe you can explain what you're trying to accomplish here. Apr 14, 2018 at 21:48
  • I think i made mistake there.. let me check, Thanks
    – Ankit Jain
    Apr 15, 2018 at 18:46
  • I fixed that but still i am getting the same error, Every time i added new content, i need to clear cache to make my new content to get my custom suggestion and adopt that new suggestion.
    – Ankit Jain
    Apr 16, 2018 at 20:42

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.