getgrav / grav-plugin-langswitcher

Grav LangSwitcher Plugin
https://getgrav.org
MIT License
28 stars 26 forks source link

Where to add language selector code? #61

Closed key-notes closed 3 years ago

key-notes commented 3 years ago

Hello, I'm a new user of Grav, though I'm not new to programming or to flat file CMSs. I created a multilingual site and need to display a language selector. To this end, I installed and activated the LangSwitcher plugin, which requires adding {% include 'partials/langswitcher.hreflang.html.twig' %} to the theme. My site uses the Typhoon theme, which appears to be the current state of the art for Grav.

Could anyone kindly tell me exactly where this code (which path and file, which line number?) should go to add a language selector to the upper right of the navbar in both desktop and mobile views? I've been trying to add it to different files but Grav keeps returning error messages. Evidently I don't yet know how Grav parses template files. Many thanks in advance for any assistance.

rhukster commented 3 years ago

Because Typhoon uses a sophisticated menu system, I am planning on adding a flexible way to add menu items to the default page navigation. However, as of right now, the best way to add it to Typhoon is to add the include after this div in the templates/partials/header.html.twig template:

      {% if theme_config.menu.primary_location == 'header' %}
        <div class="hidden h-full md:flex md:flex-grow justify-end">
          {% include 'partials/navigation.html.twig' %}
          {% include 'partials/langswitcher.html.twig' %}
        </div>
      {% endif %}

You will also need to disable the built-in CSS option in the lang-switcher plugin, then add your own CSS to style it as you want.

If you are looking for a typhoon specific styling, please create an issue here: github.com/getgrav/grav-premium-issues/issues

key-notes commented 3 years ago

@rhukster: Thanks very much. This is really strange, as I had already tried adding the code snippet there. I tried again, and yet again nothing changes—no additional content appears in the navbar or anywhere else.

Update: This appears to be an issue of CSS incompatibility between the LangSwitcher plugin and the Typhoon theme. The language links are displayed only if LangSwitcher's built-in CSS is disabled; otherwise the code is technically there, but the actual links are hidden. Strange.

Unfortunately this doesn't seem to be the only plugin that struggles with Typhoon. I bought Typhoon because it seemed to be the best-supported "official" template and also to support Grav's development, but so far I've been experiencing some significant issues with it. Hopefully these can get worked out soon enough.

rhukster commented 3 years ago

Oh I realized that i fixed an issue with your include after I had already pasted it in the message.. You were trying to include the langswitcher.hreflang.html.twig file which is only for the alt href lang link tags (invisible), when you should be including the langswitcher.html.twig which displays the linkable languages.

I can provide typhoon-specific styling, but its best to do that on the premium issues tracker rather than here as it requires some custom CSS.

I plan on adding support for login + langswitcher in a more integrated solution in the next release of Typhoon, it's just not quite ready yet.

key-notes commented 3 years ago

Yes, actually I caught that too, although I'd want to include the language switcher in both the standard navbar and the hamburger nav on mobile. But the CSS issue is the real problem here.

I'll look for the premium issues tracker—sorry, I'm completely new to Grav and to this community. Trying to find my way around.