Language Menu icon with language plugin

Hi

I’m new to grav and I’m trying to get an icon without text in the pinpress theme menu.
It should also contain the language plugin if possible.

Is it possible to create a page and include the twig language plugin code in it?
The icon works, but how can I get rid of the text? Only for the language menu, not for every menu.

Thanks

@Dans,

[…] I’m trying to get an icon without text in the pinpress theme menu.
It should also contain the language plugin if possible.

That’s possible but you’ll have to edit the themes templates for that. But before doing so, you should create a child theme to prevent the loss of your edits.

Is it possible to create a page and include the twig language plugin code in it?

Yes, Twig code can be executed inside a page’s Markdown, but I don’t thinks that is what you need.

The icon works, but how can I get rid of the text?

How/where did you add an icon? Do you have some code to share?

Only for the language menu, not for every menu.

I’m afraid I don’t understand what you’re trying to achieve.

Would you mind creating a screenshot of your site and edit the screenshot to show your intensions?

Hey

Thanks for reply!

That’s possible but you’ll have to edit the themes templates for that. But before doing so, you should create a child theme to prevent the loss of your edits.

That’s all done

How/where did you add an icon? Do you have some code to share?

I created a page under root-parent with icon: language but the icon is in front of the word language. I would like to have only the icon.
At the moment, the page is an External template.

language_icon

As you can see in the screenshot right. That’s this Grav LangSwitcher Plugin and the code {% include 'partials/langswitcher.html.twig' %} is in header.html.twig at the moment.

So I would like to have only the language icon in the menu and the plugin as the links.

@Dans, Still not sure… You have language icon in the menu and a dropdown with the English flag. That’s is confusing to me…

Anyway, if you are looking for something like this:
Untitled

I did the following:

  • Downloaded language icon from http://www.languageicon.org/
  • Copied image from zip into folder /user/themes/pinpress/images/
  • Renamed language icon to language.jpg
  • Edited user/themes/pinpress/templates/partials/navigation.html.twig and replaced lines 40-42 with:
    <a href="{{ mitem.url }}">
      {% if mitem.text == 'language' %}
        {{ media['theme://images/language.jpg'].resize(20,20).html() | raw }}
      {% else %}
        {{ mitem.text }}
      {% endif %}
    </a>
    
  • Edited user/config/site.yaml and added:
    menu:
      - url: '#'  # Or any url you need
        text: language
    

Off course, in your case, the image should be in your child theme.

Still not sure… You have language icon in the menu and a dropdown with the English flag. That’s is confusing to me…

This is just a test. The dropdown with flag is just the plugin/code. I’m trying to include this now into the menu.

Thanks for the code. That was very helpful! I changed your/default code into:

<a href="{{ mitem.url }}">
    {{ mitem.text }}<i class="fa fa-{{ mitem.icon }}"></i>
</a>

and

- url: '#'  # Or any url you need
  icon: language

because I’m using fork awesome icons.

So how can I get the plugin code {% include 'partials/language-selector.html.twig' %} into the - url: '#' ?

@pamtbaau

Hey
Are you able to help me with it?

@Dans, Roughly, you should be able to create an extra menu item consisting of the language icon icon20x24px-exported-transparent, which, on click, shows a dropdown of language links generated by the langswitchter plugin, using the followong approach:

  1. If dropdowns are supported and needs to be enabled, first enabled it in /user/config/themes/pinpress.yaml.
  2. Create two child pages to one of the existing top-level pages
  3. In the browser, look at how the dropdown for the page with child page(s) has been created.
  4. Edit the template for plugin LangSwitcher to create a list of language links resembling the list of links seen in step 3.
  5. In navigation.html.twig (after line 44) of Pinpress, create a new menu-item with an outer structure as seen in step 3 and {% include %} the edited Langswitcher template to insert the language links.
  6. You will probably have to iterate steps 4 and 5 a few times to get the dropdown menu right.

Hey @pamtbaau

I’m trying a different way at the moment.
I changed the language-selector.html.twig file (line 2-10) to:

    <i class="fa fa-language btn" data-dropdown="langSelectorList">
        {% if language_display.button == 'default' or language_display.button == 'flag' %}
        {% endif %}
        {% if language_display.button == 'default' or language_display.button == 'name' %}
        {% endif %}
        <i class="fa fa-caret-down"></i>
    </i>

My problem is now I can’t get it inline of the menu by adding the code {% include 'partials/langswitcher.html.twig' %} at line 27 in the navigation.html.twig file:

    {% if theme_config.dropdown.enabled %}
        {{ _self.loop(pages) }}{% include 'partials/language-selector.html.twig' %}
    {% else %}

language-menu

Is there a proper way or should I change the css?

@Dans, Again, you are confusing me… Throughout this thread you seem to be mixing two different language plugins: LangSwitcher and the Language Selector plugin.

Please help the community to help you by creating clear and succinct questions…

Anyway, because it is still not clear how the end-result should look like, this is the last thing I’ll add to this thread…

  • Create a child theme of Pinpress.
  • Install the LangSwitcher plugin.
  • Download language icon from http://www.languageicon.org
  • Copy image from zip into folder /user/themes/mytheme/images/
  • Rename language icon to language.jpg
  • Copy template user/themes/pinpress/templates/partials/navigation.html.twig into your own theme’s folder user/themes/mytheme/templates/partials/
  • In template user/themes/mytheme/templates/partials/navigation.html.twig add the following below line 44:
    <li class="dropdown">
      <a class="dropdown-toggle" data-toggle="dropdown">
        {{ media['theme://images/language.jpg'].resize(20,20).html() | raw }}
        <i class="fa fa-caret-down"></i>
      </a>
      <ul class="dropdown-menu">
        {% include 'partials/langswitcher.html.twig' %}
      </ul>
    </li>
    
  • Copy from plugin LangSwitcher, template /user/plugins/langswitcher/templates/partials/langswitcher.html.twig into your own themes folder user/themes/mytheme/templates/partials/
  • In template langswitcher.html.twig comment out the first and last line:
    {# <ul class="langswitcher"> #}
    ...
    {# </ul> #}
    
  • The menu will now look like this:
    Untitled

Note, I’m not using flags because it is not a good idea to use them.

This is really very confusing. I always thought I was using the LangSwitcher plugin as I mentioned in post 3. I was wondering why the code {% include 'partials/langswitcher.html.twig' %} wasn’t working and I saw that it was just the wrong filename. I didn’t pay any further attention to it. I thought there was only one language plugin and I thought I installed the LangSwitcher plugin. I’m very sorry. And I always thought, why is this so confusing. I just want the language in the menu :smiley:

Anyway, the goal was still the same. Because of you, I finally made it. Again, I’m really sorry for giving you a few headaches …