Search the FirstSpirit Knowledge Base
Hello Team,
I have a language dependent 2 URL configured in the project settings for EN and DE language separately.
Based on the Selection of the Content-Creator selection language Content-creator page is loaded to the user.
I have to get the language dependent values based on CC page is loaded to the user.
Global Settings:
CMS_INPUT_TEXT name:ps_webchat_endpoint_url
Can't assign values to CMS_SET and How to get the DE value of Project-settings in English page Content??
Code:
$CMS_IF(#global.is("WEBEDIT"))$
$CMS_SET(editorLanguage_endpoint_url,"")$
<script type="application/javascript">
console.log(top.WE_API.Common.getLocale() + " - " +top.WE_API.Common.getDisplayLanguage());
$CMS_IF(!ps_webchat_endpoint_url.isEmpty)$
if(top.WE_API.Common.getLocale().toString() == "de"){
$CMS_SET(editorLanguage_endpoint_url)$$CMS_VALUE(#global.page.getFormData().get(#global.project.languages.filter(x -> !x.masterLanguage), "ps_webchat_endpoint_url").get())$$CMS_END_SET$
}else{
$CMS_SET(editorLanguage_endpoint_url)$$CMS_VALUE(#global.page.getFormData().get(#global.project.masterLanguage, "ps_webchat_endpoint_url").get())$$CMS_END_SET$
}
$CMS_END_IF$
</script>
$CMS_END_IF$
Thank you.
Hi Siva,
the filter() method creates a new array with all elements that pass the test specified in the function, therefore you need to select the first element.
.filter(x -> !x.masterLanguage) convert to -> .filter(x -> !x.masterLanguage)[0]
I haven't tested your approach, but I usually extract ProjectSettings data in this way:
$CMS_VALUE(
#global.project.userService
.getStore(class("de.espirit.firstspirit.access.store.Store$Type").GLOBALSTORE, #global.release)
.projectProperties
.formData.get(#global.project.languages.filter(lang -> lang.abbreviation == "DE")[0], "ps_webchat_endpoint_url").get()
)$
or, for the master language, you can use, as you already did:#global.project.masterLanguage
Also, for the set you can use shorter version: $CMS_SET(set_editorLanguage_endpoint_url, #global.project.userService...)$
FirstSpirit Online Documentation - CMS_SET
Best,
Dragan
Hi Siva,
the filter() method creates a new array with all elements that pass the test specified in the function, therefore you need to select the first element.
.filter(x -> !x.masterLanguage) convert to -> .filter(x -> !x.masterLanguage)[0]
I haven't tested your approach, but I usually extract ProjectSettings data in this way:
$CMS_VALUE(
#global.project.userService
.getStore(class("de.espirit.firstspirit.access.store.Store$Type").GLOBALSTORE, #global.release)
.projectProperties
.formData.get(#global.project.languages.filter(lang -> lang.abbreviation == "DE")[0], "ps_webchat_endpoint_url").get()
)$
or, for the master language, you can use, as you already did:#global.project.masterLanguage
Also, for the set you can use shorter version: $CMS_SET(set_editorLanguage_endpoint_url, #global.project.userService...)$
FirstSpirit Online Documentation - CMS_SET
Best,
Dragan
Hi Rakita,
Thank you for your reply and time.
It really helped me to sole the problem.
Assigned the CMS_VALUE to js variable before the js if condition.
function getLocaleLanguageUrl(){
let localeLangUrl;
$CMS_SET(set_editorLanguage_endpoint_url,"")$
$CMS_SET(set_editorLanguage_endpoint_url, #global.project.userService.getStore(class("de.espirit.firstspirit.access.store.Store$Type").GLOBALSTORE, #global.release).projectProperties.formData.get(#global.project.languages.filter(lang -> lang.abbreviation.toLowerCase() == "de")[0], "ps_webchat_endpoint_url").get())$
const langDE = '$CMS_VALUE(set_editorLanguage_endpoint_url)$';
$CMS_SET(set_editorLanguage_endpoint_url, #global.project.userService.getStore(class("de.espirit.firstspirit.access.store.Store$Type").GLOBALSTORE, #global.release).projectProperties.formData.get(#global.project.masterLanguage, "ps_webchat_endpoint_url").get())$
const langOthers = '$CMS_VALUE(set_editorLanguage_endpoint_url)$';
if(top.WE_API.Common.getLocale().toString() == "de"){
localeLangUrl = langDE;
}
if(top.WE_API.Common.getLocale().toString() != "de"){
localeLangUrl = langOthers;
}
return localeLangUrl;
}
Thanks and Regards,
Siva