PandaUA
Joined 10 years ago
Joined 10 years ago
I believe the reason it was always going to the community page was because you had a "/" at the front of your anchor url. If you removed the "/" from the front of the anchor tag's href attribute, it would redirect you to the same page you were on:
<ul class="header__lingvs"> <li><a class="sw_lang" title="Russian" href="?profile.language=ru">Rus</a></li> <li><a class="sw_lang" title="Ukrainian" href="?profile.language=uk">Ukr</a></li> </ul>
However, it will remove any query parameters that are already in the URL when you do that, so you probably would want to programmatically create the URL (as Claudius mentioned in his reply). Something like this maybe (I've included a couple really crude functions which might have bugs so use at your own risk):
<#function appendParam bf lang>
<#if bf?ends_with("&")>
<#return bf + "profile.language=" + lang />
<#else>
<#return bf + "&profile.language=" + lang />
</#if>
</#function>
<#function getCurrentPageUrlWithNewLanguage lang>
<#if http.request.url?contains("?")>
<#if http.request.url?contains("profile.language=")>
<#assign bf = http.request.url?keep_before("profile.language=") />
<#assign af = http.request.url?keep_after("profile.language=") />
<#if af?contains("&")>
<#return appendParam(bf, lang) + "&" + af?keep_after("&") />
<#else>
<#return appendParam(bf, lang) />
</#if>
<#else>
<#return http.request.url + "&profile.language=" + lang />
</#if>
<#else>
<#return http.request.url + "?profile.language=" + lang />
</#if>
</#function>
<ul class="header__lingvs">
<li><a class="sw_lang" title="Russian" href="${getCurrentPageUrlWithNewLanguage("ru")}">Rus</a></li>
<li><a class="sw_lang" title="Ukrainian" href="${getCurrentPageUrlWithNewLanguage("uk")}">Ukr</a></li>
</ul>
-Doug
PandaUA - Seems like custom component is the only option you have here. You need to override these 2 components. Code is fine and fetch the location of the user.
Links for overriding a component - http://community.lithium.com/t5/Components-endpoints-and-the/Using-override-to-change-core-components/ta-p/61358