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.

     

  • 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"

      • Parshant's avatar
        Parshant
        Boss

        matthieul, replace your code with this in first condition

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

         It will work like a charm.