Master page

Theodoulos Iacovou asked on February 19, 2020 18:06

My website has 3 languages.How can i add a unique script in each master page of each language?

Recent Answers


Brenden Kehren answered on February 19, 2020 18:11

I'd suggest using one master page and add 3 different javascript webparts and have the visiblity property equal to

LocalizationContext.CurrentCulture.CultureCode == 'en-us'
or
LocalizationContext.CurrentCulture.CultureCode == 'en-gb'
or whatever your localization codes are. Pretty simple solution vs. managing 3 different templates.

2 votesVote for this answer Mark as a Correct answer

Juraj Ondrus answered on February 20, 2020 07:10

Or, you can create three separate master page templates and use them separately for each culture version. Sample screen shot. Documentation link.

0 votesVote for this answer Mark as a Correct answer

Theodoulos Iacovou answered on February 20, 2020 09:02 (last edited on February 20, 2020 09:06)

I have implement the separate master page but i want to add a unique java script code on each "head" of every master page.

0 votesVote for this answer Mark as a Correct answer

Juraj Ondrus answered on February 20, 2020 09:44

I see, the head section is the same for all languages. In this case, use the macro and IF condition to check the current culture and render appropriate code as suggested by Brenden. The macro could look like this:

{% x = LocalizationContext.CurrentCulture.CultureCode; if (x == "en-us") {return "code for US"} else { if (x == "en-gb") {return "code for UK"} else {return " code for AU"}

Of course, in the head section must be a valid HTML code for this part of the HTML.

0 votesVote for this answer Mark as a Correct answer

Theodoulos Iacovou answered on February 20, 2020 10:01

So {% x = LocalizationContext.CurrentCulture.CultureCode; if (x == "en-us") {return "javascriptcode"} else { if (x == "el-gr") {return "javascriptcode"} ?

0 votesVote for this answer Mark as a Correct answer

Theodoulos Iacovou answered on February 20, 2020 10:51

This is working {% x = LocalizationContext.CurrentCulture.CultureCode; if (x == "en-us") {return "javascriptcode"}, the else is not working

0 votesVote for this answer Mark as a Correct answer

Juraj Ondrus answered on February 20, 2020 12:22

well, what is the exact macro code? Keep in mind the HTML markup and so on - maybe you are breaking the macro syntax. Use the macro debug to see how is the macro evaluated and resolved. It depends what "not working" means too - are there any errors? E.g. in the Event log? You may also want to use open condition macros. Please, see the macro syntax page.

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on February 20, 2020 13:20

Theodoulos,

You've already wasted too much time on this by wanting to use the HEAD section of the page. Just use the we parts as I suggested. Since you are using 3 separate templates, you don't even need a visibility macro.

1 votesVote for this answer Mark as a Correct answer

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