CMS Development

DanBQ
Participant | Elite Partner
Participant | Elite Partner

Using if statements to only show language switcher url if there is a translated page in HubSpot

Hi all,

 

Is it possible to have a statement in my language switcher module so that only if there is a translated page in that language available to display that language option in the switcher, if not don't display that language option in the dropdown?

 

Here is my code:

<div class="navbar">
  <div class="dropdown">
    <button class="dropbtn">
     <i class="fa fa-globe"></i>
    </button>
    <div class="language-dropdown-content">
     {% if content.language.langauageTag == "en-us" %} <a href="/{{ content.translated_content['en-us'].slug || '' }}">Americas</a> {% endif %}
     <a href="/{{ content.translated_content['en-gb'].slug || 'en-gb' }}/{{ request.path|split('/', 2)|last }}">EMEA</a>
    </div>
  </div> 
</div>

That if statement isn't working. It's just turning the switcher off on every page.

 

This is the website: https://www.cogencyglobal.com/en-gb/

 

Many thanks!

0 Upvotes
4 Replies 4
LucBenayoun
Participant

Using if statements to only show language switcher url if there is a translated page in HubSpot

Hey! 

 

I think a simple solution like this should work. Let me know if it's working! 

{% if content.translated_language|length > 0 %}
// Language switcher code
{% endif %}

 

Cheers 🙂

mjdiamzon
Member | Partner
Member | Partner

Using if statements to only show language switcher url if there is a translated page in HubSpot

Your code works, just correct the 'langaugeTag' spelling.

Jsum
Key Advisor

Using if statements to only show language switcher url if there is a translated page in HubSpot

@DanBQ ,

 

I ran into this problem myself. I searched developer info and all of the docs. As far as I can tell, There is no way to to determine whether a page has translations or not. an ugly solution would be to use the modules html wrapper to check the page name for page's that have translations. something like.

{% if content.name == 'page name 1' or if content.name == 'page name 2' %}
    {{html}}
{% endif %}

Let us know if you find a better solution.

sharonlicari
Community Manager
Community Manager

Using if statements to only show language switcher url if there is a translated page in HubSpot

Hey @DanBQ 

 

I apologize for the delay in getting back to you. I will tag a few of our experts to give you some tips about this.           

 

Hey @derekcavaliero @Jsum could you please share your knowledge with @DanBQ          

 

Thank you,

Sharon


Did you know that the Community is available in other languages?
Join regional conversations by changing your language settings !




0 Upvotes