I have a block for the language switcher. I want to override the links in it. I can override a specific language switcher block's markup, and I can override the links markup in all language switcher blocks, but I can't override "$links markup in language switcher block delta 1".

Do I have to use a template suggestion to do this? If so, how should I approach this? With the core templates, I've tried to dig down with: blocks, into links, but only get as far as {{ content }}; and go up with links into blocks, but I can't be specific and target a block that way.

Current templates I've got:

  • block--languageswitcher.html.twig (targets block with delta 1, but can't theme links)
  • links--language-block.html.twig (targets links in all switchers, unspecific)

Use case: Specifically, I'm trying to override the switcher so I can have country codes in an inline list instead of country names in an unordered list. e.g. EN | FR | IT Obviously, I could overwrite all the switcher blocks but it doesn't seem right; it's certainly inelegant.

  • Have you tried kinting the two theme hooks for the above? Specifically, block and links__language_block. Those two yield quite a bit of info that might be able to be leveraged in a theme hook suggestion alter. – Danny Englander Jul 6 '16 at 14:29
  • TBH I'm not entirely sure what you mean, and my theme-fu is very lacking. Could you flesh that out a little bit please? :) – NikLP Jul 7 '16 at 8:56
  • Hey if you like, join drupaltwig-slack.herokuapp.com and I can give you some tips over there. Also lots of others who might be able to help as well. – Danny Englander Jul 7 '16 at 13:49
  • 1
    You want to enable Twig debugging but it sounds like you have that set already. Next look at your theme hooks in web inspector and then in your theme, do something like function MYTHEME_preprocess_links__language_block(&$vars) { kint($vars); }. That should yield a good amount of info and you can do that for block too. You can then create theme hooks with MYTHEME_theme_suggestions_[THE_HOOK]_alter. Sorry I don't have a specific answer for you but that's how I would approach it. I've written a few posts about this on my blog. – Danny Englander Jul 7 '16 at 23:05
  • 1
    Finally got around to 'making it so' - I actually already had a block preprocess in there which I managed to use to alter the links by a specific block ID, I'll post the code in a blog and refer to it here. Thanks! – NikLP Oct 25 '16 at 17:06

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.