Hi folks.
there is probably a simple answer to this but I can’t find anything in the wiki or forum. Please advise if this should be posted elsewhere.
I am building a multilingual site. Each doc is populated with language-specific content from a table in the MODx db, using a snippet which is called from the template: [!LanguageContent?!].
The snippet displays the language links, using [!LanguageContent? &type=`choice`!], and clicking one of these re-calls the current page but using the selected language to fetch the content from the db, using [!LanguageContent? &type=`content`!]. (ie, using the same snippet twice on the page).
The links are created as:
echo'<a href="[~[*id*]~]&do=change&lang='.$language_id.'">'.$language'."</a>\n";
(I’ve simplified this by taking out some html attributes).
and end up as:
<div id='flags'>
<a href="index.php?id=1&do=change&lang=1">English</a>
<a href="index.php?id=1&do=change&lang=2">Spanish</a>
<a href="index.php?id=1&do=change&lang=4">German</a>
</div>
This works fine when changing language on the same page, just getting the language from $_REQUEST[’lang’] and fetching the appropriate content from the db, but it is when I want to go to another page in the menu that this system comes unstuck, as I have not added the "&do=change&lang=2" etc to the menu links (created using Wayfinder).
I tried using the value of $language_id to set a placeholder, which I could then pick up in the snippet on the next page, but the placeholder seems to expire by the time I get to the next page. Does this mean that placeholders only last as long as the current page exists and are then disposed of?
(If not, then should I be able to pick up the placeholder in Wayfinder and add the language ID to the menu links, as above?)
In summary: Is there any way of persisting a variable on the server, for the current session, which can then be used when the next browser request is made?
There are may be snippets available to do this sort of thing, which might be useful, but I would love to know exactly what happens to placeholders; how long do they last and can they be used by other snippets and between page requests?
Very much obliged if anyone can answer this for me, thanks