Copied to clipboard

Flag this post as spam?

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


  • awm 187 posts 376 karma points
    Sep 10, 2012 @ 17:40
    awm
    0

    Mobile websites and altTemplates

    Hi guys,

    I'm having to build a site that renders different content depending on device being used. Ideally I'd like the server to be able to determine the device and serve up the relevant template (thereby avoiding rendering rendundant elements on mobile devices).

    I'm thinking that I'd build the site, assign the default templates and then within the master template, run a server-side check to see the device and then switch the template based on a simple name convention ie:

    var template = GetCurrentTemplate();
    if desktop
      load regular template
    else if ipad
      load template + "-ipad"
    else if mobile
      load template + "-mob"

    So for every template I'd have an ipad/mobile one created too. I'd somehow detect the device on the server and then render the correct template.

    Is this a viable approach? Has anyone managed to do something like this?

    The only major problem I can forsee is the url-rewriting.. is it possible to create a url-rewriting rule that'd strip the altTemplate querstring from the browser window?

  • Rich Green 2246 posts 4008 karma points
    Sep 10, 2012 @ 18:04
  • awm 187 posts 376 karma points
    Sep 12, 2012 @ 23:21
    awm
    0

    Thanks Rich but I'm not sure if that's what I'm after. It'd be fine if I just had one set of mobile templates to worry about as I could redirect to a mobile specific domain and serve up the correct templates.

    The issue I'm having is that I have 5 different templates that need to be rendered for different devices/resolutions. From what I gather, if I was to take the above approach I'd have to have 5 separate content trees, with each tree having a different hostname for that particular device? Combine that with the fact I have two languages, that'd mean 10(?!) trees?

    I figured the easiest thing would be to have two content trees for each language, and then in the umbraco masterpage run a check to figure out what device is viewing the site, then render the content with the correct template. It seems I might be able to do this using the altTemplate querystring but I wonder if anyone has done this before and if so, how it worked out? Also, is it possible to load a template programmatically? I can't seem to find any info on it..

    Ta

Please Sign in or register to post replies

Write your reply to:

Draft