0

I've been trying to look for a way on how to optimize theme suggestions for different languages. The code below is a snippet of what I have been working on.

One is for english and one is for Spanish. Is there a way I can minimize this into a single code instead of breaking it down for multiple languages?

// Template based on current url
// News Press Room

if ($current_url == '/iom/news-press-room') {
    $suggestions[] = 'page__news_press_room';
}

// News Press Room(Spanish)

if ($current_url == '/iom/es/news-press-room') {
    $suggestions[] = 'page__news_press_room';
}
7
  • Is this Drupal 8 or 7? Commented Sep 17, 2018 at 7:39
  • @IsmailCherri yes, this is Drupal 8
    – clestcruz
    Commented Sep 17, 2018 at 7:43
  • 1
    I think the question title could be misunderstood. If your code should not depend on the language you could try to get the information from the current route instead of the current path. Which is preferable in most cases anyway, because normally a page is based on a resolved route, not on a path.
    – 4uk4
    Commented Sep 17, 2018 at 12:10
  • 1
    You didn't provide any details about the content you display. For example if this is a node, then you can get the node id from the raw route parameter node, independently from the alias or language prefix in the path.
    – 4uk4
    Commented Sep 18, 2018 at 11:12
  • 1
    Yes, because there may be dozens of paths leading to one node.
    – 4uk4
    Commented Sep 18, 2018 at 11:37

1 Answer 1

1

Check the example in hook_theme_suggestions_alter() for language (second one below)
You can add more specific suggestions by appending the content type.

Your Answer

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

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