Forum Discussion

matthieul's avatar
7 years ago

redirection many locale

Hello Lithosphere,

Context : I have a default locale (en) and an other fr

I have to set a default locale from user preferences and redirect it if user go to root url 

My problem : 

My code works well but not for root page, and if I disable the first line, my community will be down.

Can you help me ?

My code : 

<#if page.name == 'CommunityPage' >
<#assign preferred_lang = rest("/users/id/${user.id}/profiles/name/locale").value?trim />
<#if preferred_lang != '' >
<#if preferred_lang == 'fr' || preferred_lang == 'France' >
<#assign redirect_url = '/t5/FR/ct-p/francais' />
<#elseif preferred_lang?contains('en') || preferred_lang == 'English' >
<#assign redirect_url = '/t5/EN/ct-p/english' />
<#else>
<#assign redirect_url = '/t5/EN/ct-p/english' />
</#if>
<#else>
<#assign redirect_url = '/t5/EN/ct-p/english' />
</#if>

${http.response.setRedirectUrl(redirect_url)}
</#if>



 

  • Parshant's avatar
    Parshant
    7 years ago

    matthieul, replace your code with this in first condition

    <#if !user.anonymous && page.name == "CommunityPage">

     It will work like a charm.

     

4 Replies

  • matthieul may I ask how your code "works well", but not on root level? Because all the code would do is work on root level (e.g. on community level which you do by limiting your logic to the CommunityPage).

    Maybe you need to specify more clearly what you mean by "root" level?

  • Lu, my "root" level is community.stage.####.com.

    If I request this url my code is not exectuted while I have a page "Community Page"

  • luk's avatar
    luk
    Boss
    7 years ago

    matthieul Are you familiar with browser dev-console/inspector? If so, check the quilt class in the body HTML-tag, does it say "CommunityPage" when you are on community.stage.####.com?

    It still doesn't make much sense, because if you say it works well, where would that be the case then? E.g. where is the page where your code works if not community.stage.####.com? Usually this is the CommunityPage, and there can only be one in the entire community...

  • Parshant's avatar
    Parshant
    Boss
    7 years ago

    matthieul, replace your code with this in first condition

    <#if !user.anonymous && page.name == "CommunityPage">

     It will work like a charm.