Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Nic Wise 51 posts 85 karma points
    Jun 27, 2011 @ 17:54
    Nic Wise
    0

    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

  • Rich Green 2246 posts 4008 karma points
    Jun 27, 2011 @ 18:20
    Rich Green
    0

    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

  • Nic Wise 51 posts 85 karma points
    Jun 28, 2011 @ 11:09
    Nic Wise
    0

    Thanks Rich, I'll have a look at the slides.

  • Rich Green 2246 posts 4008 karma points
    Jun 28, 2011 @ 11:12
    Rich Green
    0

    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

  • Nic Wise 51 posts 85 karma points
    Jun 28, 2011 @ 12:36
    Nic Wise
    0

    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.

  • Nic Wise 51 posts 85 karma points
    Jun 28, 2011 @ 17:30
    Nic Wise
    0

    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!

Please Sign in or register to post replies

Write your reply to:

Draft