0

When I use the this code; <?php $block = module_invoke('locale', 'block_view', 'language'); print $block['content']; ?>, I get the following output. But I'd like to add another class to ul.

<ul class="language-switcher-locale-url"><li class="en first"><a href="/en" class="language-link" xml:lang="en">EN</a></li>
<li class="tr last active"><a href="/ru" class="language-link active" xml:lang="ru">RU</a></li>
</ul>
0

Have you tried rendering the content instead?

<?php print render($block['content']); ?>

That, combined with the Block Class module should at least allow you to add a class to the wrapper, which is the next best thing to overriding the theming of the actual UL.

0

1 Enable debugging

in your sites/default/services.yml

twig.config:
  debug: true

2 Clear cache

3 enable your browser's HTML comments

in chrome it is something like Preferences > Elements > Show HTML comments

4 find out the template used for this block

by looking in the inspector you can find suggestions on how to override this template

enter image description here

in my case there is a suggestion links--language-block.html.twig

5 copy original template

either from core/modules/system/templates/links.html.twig or from your themes template directory if you are subtheming

Paste into your theme's template directory and name it as suggested

6 modify the template

and addClass to UL

This

  <ul{{ attributes }}>

becomes

  <ul{{ attributes.addClass("my-class") }}>

7 clear cache again

in your inspector you should see your template and your class

enter image description here

To find out more about twig name conventions and using attributes in templates

0

Some trial and error but the following allowed me to get the right format;

<?php $block = module_invoke('locale', 'block_view', 'language'); $content =  $block['content']; $content = str_replace("language-switcher-locale-url","language-switcher-locale-url dropdown-menu",$content); print $content;?>

Your Answer

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

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