Preserve QueryString in language toggle

Tristan Geilich asked on November 23, 2016 22:10

Hello,

I'm trying to toggle between languages in Web Part Properties (Repeater) -> HTML Envelope:

<span class="language-toggle">
  <a class="link" href="{% CurrentDocument.RelativeURL.Replace("~/fr/", "/en/") #%}">{$sitename.global.english$}</a> | 
  <a class="link" href="{% CurrentDocument.RelativeURL.Replace("~/en/", "/fr/") #%}">{$sitename.global.francais$}</a>
</span>

The problem I'm running into is that the QueryString is lost when switching between languages. For example toggling from English to French will result in:

../en/products/search?searchText=value1

to:

../fr/products/search

Any idea how I can preserve the QueryString?

Correct Answer

Jan Hermann answered on November 23, 2016 22:57

Try {%QueryString%}

0 votesVote for this answer Unmark Correct answer

Recent Answers


Tristan Geilich answered on November 23, 2016 23:48

Awesome! Thank you, that's what I was looking for.

0 votesVote for this answer Mark as a Correct answer

Peter Mogilnitski answered on November 23, 2016 23:50

I am not sure that you need to preserve the search text because it probably doesn't make any sense for the other languages. Why would you search French word in English? If you still need it,do like Jan suggested above or {%searchtext%}. Add this to your macro with relative Url

0 votesVote for this answer Mark as a Correct answer

Tristan Geilich answered on November 24, 2016 20:34 (last edited on November 24, 2016 20:46)

In this particular case, the contents of the search are the same for both languages. I am however running into an issue where the {%QueryString%} not only adds on the the QueryString, but also the alias path. This is causing problems in other pages. E.g.

../en/products/search?searchText=value1

becomes:

../en/products/search?searchText=value1&aliaspath=%2fdomain-ca%2fProducts%2fSearch

Is there a way to exclude the aliaspath? I'm not actually sure why this is being added, as it isn't part of the original querystring.

0 votesVote for this answer Mark as a Correct answer

Jan Hermann answered on November 25, 2016 16:49 (last edited on December 10, 2019 02:30)

If you need just that search query string use this:

{% CurrentDocument.RelativeURL.Replace("~/fr/", "/en/") + "?searchText=" + QueryString.GetValue("searchText") |(identity)GlobalAdministrator%}

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.