How to dynamically assign page templates to pages based on criteria such as user's country

Jeremy Warach asked on June 29, 2016 20:33

We are interested in changing various aspects of the user experience based on information such as the user's country (determined by IP address). We would like to change the master page template of the site and dynamically determine which of several page templates to apply to various pages.

Do you have a "best practice" for this type of behavior? Essentially we want to use a single document database to drive different templated versions of the site, based on information about the user viewing it.

Thank you.

Recent Answers


Trevor Fayas answered on June 29, 2016 20:44

One thing to try is to use a control of the Page Placeholder.

Although the web part doesn't have these options, the actual page placeholder control has the ability to designate the template (which you can assign dynamically) and the node you are 'placing'

You would have to test, but you can try adding a page placeholder at the root that would load in the 'root' with a different template depending.

below is a sample of kind of what you are looking at.

<%@ Register Src="~/CMSWebParts/General/pageplaceholder.ascx" TagName="pageholder" TagPrefix="uc1" %>
  <uc1:pageholder runat="server" ID="myPlaceholder" Path="/"/>
  <script runat="server">
protected override void OnInit(EventArgs e)
{
  // Dynamically set the page template here
  myPlaceholder.PageTemplate = "TheTemplateCodeName";
}
</script>
0 votesVote for this answer Mark as a Correct answer

Jeremy Warach answered on June 29, 2016 20:47

Would this allow us to change the Master Page Template as well?

0 votesVote for this answer Mark as a Correct answer

Trevor Fayas answered on June 29, 2016 22:37

It's tricky because i've never replaced the existing, it may require you to use the ASPX+Portal for the master page so you can set it there, but not sure if that messes up the ability to do portal only on the other pages.

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on June 29, 2016 23:14

Another option Trevor/Jeremy is to create a webpart which will assign/change what is needed on that masterpage vs. using aspx + portal.

1 votesVote for this answer Mark as a Correct answer

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