I have a need to pick the template I use at runtime. For example, if I have Template-A-News, I want to pick Template-A-News-Mobile based on the User Agent string, or some other thing.
Is there a hook I can put in? I have about 8 templates (news, homepage, news list, discography etc), all of which have a mobile version, so I need to look up what the requested page has set, and use the mobile equivalent.
JS and anything client side is not an option, as the devices are unlikely to have Javascript.
No problem Nic, just looked at the slides, it's the but where he talks about "Chrome templates" (not to be confused with the browser) so not sure the slides help.
He showed the actual bit of code that did it, I remember it was dead simple, but can't remember the solution off hand.
Thanks - I might just drop him an email :) MSFT people tend to be friendly.
Those slides also validated another bit of our architecture: using one box to enter (and preview) all content, and actually serving it off another (in another data center), moving it over with Courier.
Basically, put this into a .cs file in App_Code. It hooks into the UnbracoDefault base page, and gets called before the page is rendered. You can then switch the masterpage which is used by loading it via a template - basically, I'm going to have to look up the original ID (1045) and replace it with a new one (1047) - by name if I can, as I can then automate it. But if I have to have a lookup table somewhere, thats better than nothing!
Selecting a template at runtime
Hi there
I have a need to pick the template I use at runtime. For example, if I have Template-A-News, I want to pick Template-A-News-Mobile based on the User Agent string, or some other thing.
Is there a hook I can put in? I have about 8 templates (news, homepage, news list, discography etc), all of which have a mobile version, so I need to look up what the requested page has set, and use the mobile equivalent.
JS and anything client side is not an option, as the devices are unlikely to have Javascript.
Any ideas? I'm using 4.7 if it helps.
Cheers
Nic
Hey Nic,
Sorry I don't have an answer right now, but I'm I'm pretty sure that MS do something like this on their TechNet site, I was a little hungover at Codegarden but pretty sure the code was relativly simple, so once the vid is up (this week I think) the answer should be in there http://codegarden11.com/sessions/day-2/slot-one/multi-environment-team-based-development-with-umbraco-at-microsoft.aspx
Rich
Thanks Rich, I'll have a look at the slides.
No problem Nic, just looked at the slides, it's the but where he talks about "Chrome templates" (not to be confused with the browser) so not sure the slides help.
He showed the actual bit of code that did it, I remember it was dead simple, but can't remember the solution off hand.
Rich
Thanks - I might just drop him an email :) MSFT people tend to be friendly.
Those slides also validated another bit of our architecture: using one box to enter (and preview) all content, and actually serving it off another (in another data center), moving it over with Courier.
I think I might have worked this out. Here's some test code:
https://gist.github.com/1051394
Basically, put this into a .cs file in App_Code. It hooks into the UnbracoDefault base page, and gets called before the page is rendered. You can then switch the masterpage which is used by loading it via a template - basically, I'm going to have to look up the original ID (1045) and replace it with a new one (1047) - by name if I can, as I can then automate it. But if I have to have a lookup table somewhere, thats better than nothing!
is working on a reply...