0

I created different menus and need them to be displayed in a node based on the language currently visited for a specific node type.

Via my theme.theme, I added the following code to retrieve the menus:

if($lang == 'pt') {
   $recipe_block = \Drupal\block\Entity\Block::load('recipespt');
   $variables['recipe_menu_block_view'] = \Drupal::entityTypeManager()->getViewBuilder('block')->view($recipe_block);            
 } elseif($lang == 'es') {
   $recipe_block = \Drupal\block\Entity\Block::load('recipeses');
   $variables['recipe_menu_block_view'] = \Drupal::entityTypeManager()->getViewBuilder('block')->view($recipe_block);     
 }

Then I went into the node template and pulled the menus:

{% if content.field_product_type['0']['#context']['value'] == 'Recipe' %}
  {{recipe_menu_block_view}}
{% else %}
  {{cocktail_menu_block_view}}
{% endif %}

When I visit the main site(English) the menu links look ok.

But when I switch language and hover over the menu, instead of seeing the URL alias I am seeing the node id.

How can I pull the menu through the .theme and see the node alias instead of the node alias?

2
  • Does the linked page definitely have an ES translation? As no translation = no alias – Leigh Jul 6 '20 at 13:01
  • Yes..at this point all the pages are translated – user agent Jul 6 '20 at 13:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.