Forum Discussion
You can use the settings context object like this:
<#assign lang = coreNode.settings.name.get(
"profile.language", "en"
) />
This will set lang to the language of this node with a default of English.
Good to see you this morning too!
- iftomkins11 years agoMaven
Awesome, thanks Kaela!
As we had talked about, I'm hoping to check the language setting of the current code against the user's current language setting on page load. If they are different, I'd take the language setting of the node, and change the user's language setting. I believe I can now write the logic with freemarker, but I have a question:
I tried accessing the REST API via jQuery before launch to change the user's profile setting. This worked on stage, but it didn't work on production. Here's an example call:
jQuery.post('/restapi/vc/users/id/' + userId + '/settings/name/profile.language/set?value=de');
If I do the same thing with freemarker, will it work on production?
<#assign response = restadmin('/restapi/vc/users/id/' + userId + '/settings/name/profile.language/set?value=de')/>
<#if response.hasError>
<#-- handle error-->
<#else>
<#-- do cool stuff -->
</#if>- Alan
- KaelaC11 years agoLithium Alumni (Retired)You can make the rest call like this:
"/users/id/"+user.id+"/profiles/name/language/set?value=de"
The rest looks good- iftomkins11 years agoMaven
AWESOME!
Just to double check, this should work on production, right?
Also, it seems to work, except that the page needs to be reloaded after for the setting change to take effect, otherwise you end up with 2 different languages being displayed on the same page. I currently have a javascript refresh set up in the following code, but is there a Freemarker page reload command to avoid the delay? I couldn't locate it on freemarker.org or on google.
<#assign nodeLanguage = coreNode.settings.name.get("profile.language", "en") />
<script>console.log('nodeLanguage','${nodeLanguage}');</script>
<#assign userLanguage = rest("/users/id/${user.id}/settings/name/profile.language").value>
<script>console.log('userLanguage','${userLanguage}');</script>
<#if nodeLanguage != userLanguage>
<#assign response = restadmin("/users/id/"+user.id+"/profiles/name/language/set?value="+nodeLanguage)/>
<script>location.reload();</script><#-- can this reload be in freemarker? -->
</#if>Thanks!
Alan
Related Content
- 12 months ago
- 11 months ago
- 9 months ago
- 2 years ago