Moving the placement of LanguageSwitcher Plugin doesnt work

Good day! I am in need of an expert when it comes to grav. So quick background, I tried installing the plugin LangSwitcher and it works flawlessly however I would like to place it beside the navigation area. No matter what I do whenever I try to move the {% include 'partials/langswitcher.html.twig' %} to where it’s suppose to be, it doesnt show at all.

Btw, Im using the default theme Quark and also, im trying to modify /templates/partials/menu-main.html.twig

Here’s my sample heading and sample declaration.

And also, if anyone can help me to add flags beside the countries I need that also.

If ever you need more information about this concern, let me know so I can send them and we can solve this together. Thank you!

@Joshua, You use the statement {% include 'partials/menu/langswitcher.html.twig' %}.

The template being included does not come with LangSwitcher.

  • Did you perhaps intend to include the template from the plugin? In that case you should be using {% include 'partials/langswitcher.html.twig' %} instead.
  • Is it perhaps a template created by yourself?
  • And what is ‘/templates/partials/menu-main.html.twig’?
  • Have you tried to fix the syntax errors?

Hey @anon76427325 my apologies for the confusion. {% include ‘partials/menu/langswitcher.html.twig’ %} is a copy of ‘partials/langswitcher.html.twig’ I tried putting it in a folder to see if it’ll work.

Also, ‘menu-main.html.twig’ is a file I made, basically it’s just the navigation bar. Im trying to include the langswitcher on the navigation.

Hey @anon76427325 by any chance, do we have an updated for this? Thank you!

@Joshua, Based on the information you have provided I have given you my suggestions. Frankly, I am out of suggestions.

Ok, last suggestion:
I don’t know why you have written your own navigation bar, but if you go back to the build-in navigation form Quark, you can place the LangSwitcher at the end of the navigation bar as follows.

  • In file /user/themes/quark/templates/partials/base.html.twig, insert {% include 'partials/langswitcher.html.twig' %} on line 56. It will then look like:
    <nav class="dropmenu animated">
     {% block header_navigation %}
        {% include 'partials/navigation.html.twig' %}
     {% endblock %}
    </nav>
    {% include 'partials/langswitcher.html.twig' %}
    

You will then need to use some css to align the navigation bar with the langswitcher output.

Also, you will need to add the langswitcher to the mobile menu, maybe below line 102. For this to align properly, you will also need to add css.

Hey @anon76427325 I tried this one. Still didnt work for me. I tried using a different plugin, Language Selector but apparently it still gives me the same result. I just dont understand why declaring any plugin after the navbar just doesnt seem to work at all.

@Joshua, I’m getting the impression something is really off in your theme.

It sure worked in my fresh Grav installation…

Would you mind trying the following:

  • create a fresh Grav 1.6.26 installation,
  • add supported languages to ‘/user/config/system.yaml’,
  • install LangSwitcher plugin,
  • and retry my latest suggestion.

Once you’ve got that working:

  • create an inherited theme and apply the changes in the inherited theme and not in Quark. If you don’t use an inherited theme, your changes will get lost when a new release of Quark arrives.
  • then apply any other changes you have made to your original site step-by-step to the new inherited theme in the new installation.

Btw, can I access your installation somehow? Github repo perhaps?

Hey @anon76427325 Hmmm I guess you’re right. This might be related to the theme. Thanks so much for the insight. Ill work on this over the weekend. Ill let you know once Ive made it work. If not, Ill share my repo with you. Again, thanks so much for helping.

Hey @anon76427325 it still didnt work for me. Ill be sending the link to my repo so you can check it out. Btw, do you mind if I send it somewhere more private? Like an email perhaps? Thank you!

@Joshua, Yes, its fine to PM me the link.

During the private conversation, there appeared to be three issues at hand:

  1. The template partial/langswitchter.html.twig is being included two times, but only one showed language items.

    The one not showing any language items was used inside a macro and according to Twig, macros have no access to template variables.
    This means the behaviour is as designed.

  2. The generated language items were not aligned with the default navbar

    This could be solved with a bit of css changing the display of the parent element using display: flexbox

  3. OP wanted to add flags to the languages which is not supported by plugin LangSwitcher.

    Here on the forum some time ago and elsewhere on the internet, it is debated if flags should be added to the language switcher.

    Personally I would not use flags:

1 Like