Copied to clipboard

Flag this post as spam?

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


  • Nathan Woulfe 447 posts 1665 karma points MVP 5x hq c-trib
    May 01, 2012 @ 00:30
    Nathan Woulfe
    0

    Mobile site options

    Hi all

    Not sure if this is entirely the right forum, but here we go anyway. I'm looking for advice as to the optimal way to approach a mobile-optimised site within 4.7/8.

    The way I see it, I could do one of the following:

    • Use responsive CSS to restyle the site for mobile visits. Pros - a single tree, single set of templates. Cons - can still mean a heavy download for mobile visits, with included elements that won't be displayed.
    • Copy the tree, put together a bit of code to update m.content tree when the content tree is updated. Pros - a distinct set of mobile templates would minimise page weight. Cons - two sets of content (even though one is automatically maintained).
    • Use alttemplate and UrlRewriting to show mobile visitors m.mydomain.com/page as the url, but serve mydomain.com/m/page, or something similar. Pros - single tree, mobile-specific templates. Cons - can it even be done?
    At present, I'm using the first option, with jQuery Mobile working its magic on mobile visits. It's limiting in that the templates were designed for screen, not handheld so I'm limited in how I can rework the layout. I'm tending towards option two.
    Anyone care to offer some insight into their experiences or preferences?
    cheers
    Nathan

     

  • Profiterole 232 posts 264 karma points
    May 01, 2012 @ 01:12
    Profiterole
    0

    Hi Nathan,

    I currently use the third option. My page are servred this way /about/mobile.aspx . With the altTemplate, we can use the /templatename.aspx and, for me, it seems pretty mobile for me. The site is accessible from m.mysite.com and urlrewrite to /homepage/mobile.aspx.

    So, everythings work fine, but, all my mobile content use the same alttemplate. If you need more than one template, you could go with mobilePage.aspx or mobileVideo.aspx.

  • Mike Chambers 636 posts 1253 karma points c-trib
    May 01, 2012 @ 10:16
    Mike Chambers
    0

    You can also sniff for mobile and automatically push to an alttemplate via overriding the masterpage setting.. (so urls remain the same for screen and mobile)

    Logic for us if mobile try and set the template of the page to it's set template+"Mobile", so same approach as Profiterole just taking one step further to maintain a single url for both mobile and desktop content.

    protected override void OnPreInit(EventArgs e)
            {
                base.OnPreInit(e);
    
                try
                {
                    if (String.IsNullOrEmpty(GetCurrentAltTemplateAlias()))
                    {
                        // using the admin specified template
                        Node currentNode = Node.GetCurrent();
                        umbraco.template template = new umbraco.template(currentNode.template);
    
                        // we're using the mobileesp.org to detect mobile/tablet items.
    
                            if (DetectTierTablet())
                            {
                                try
                                {
                                    if (umbraco.cms.businesslogic.template.Template.GetByAlias(template.TemplateAlias + "Tablet") != null)
                                    {
                                        Page.MasterPageFile = Page.MasterPageFile.Replace(".master", "Tablet.master");
                                    }
                                }
                                catch { }
                            }
                            else if (DetectMobileLong())
                            {
                                try
                                {
                                    if (umbraco.cms.businesslogic.template.Template.GetByAlias(template.TemplateAlias + "Mobile") != null)
                                    {
                                        Page.MasterPageFile = Page.MasterPageFile.Replace(".master", "Mobile.master");
                                    }
                                }
                                catch { }
                            }
    
                    }
                    else
                    {
    
                        // already using an alternative tempalte
                        //Response.Write(GetCurrentAltTemplateAlias() + "
    "); } } catch { } } public static string GetCurrentAltTemplateAlias() { return (System.Web.HttpContext.Current.Items["altTemplate"] ?? "").ToString(); }
  • Nathan Woulfe 447 posts 1665 karma points MVP 5x hq c-trib
    May 02, 2012 @ 00:59
    Nathan Woulfe
    0

    That's a tidy solution Mike, although does that nulify the ability to view the full site on a tablet/phone? I was using Session_Start to redirect to a subdomain, so subsequent requests for the main domain shouldn't then be redirected thus showing the 'full' site. 

    I like the idea of clean urls though, seamless and tidy is great! Will look into your solution, thanks.

     

    N

  • Mike Chambers 636 posts 1253 karma points c-trib
    May 02, 2012 @ 12:40
    Mike Chambers
    0

    The current implemtation I pasted above does force mobile/table view.... that's what our client wanted...

    Two workarounds that I see,

    many mobile browsers now have a desktop toggle type plugin (where by they alter the useragent sent to the site, to imitate a desktop rather than the tablet)

    Or you could add in functionaltiy to store a cookie/seesionstate varialbe to override.

    :-)

  • Nathan Woulfe 447 posts 1665 karma points MVP 5x hq c-trib
    May 08, 2012 @ 01:01
    Nathan Woulfe
    0

    Mike - I've marked your reply as the solution, after a bit of playing around I've got it working really nicely. Mobile visits are served the alt template, but are given the option, via a sessionstate variable, to switch out to the full site. So, so, so much tidier than using a subdomain. Thanks again for the direction.

     

    N

  • Ernst Utvik 123 posts 235 karma points
    Jun 01, 2012 @ 10:27
    Ernst Utvik
    0

    Seems like a great solution. My current setup checks for mobile and redirects to altTemplate but I would prefer a single url. How would I go about implementing the solution posted above? Guessing its not a usercontrol ;)

  • Nathan Woulfe 447 posts 1665 karma points MVP 5x hq c-trib
    Jun 04, 2012 @ 01:00
    Nathan Woulfe
    0

    Ernst - I'm setting the session variable in the session_start method in my global.asax (I had to exclude app_global.asax.dll for this to work - I think best practice is to use a httpmodule rather than global). The bulk of the work is happening in default.aspx, in the OnPreInit method, similar to Mike's example. I'm also using jQuery Mobile to handle presentation, so can treat phone or tablet as one and let css handle the different screen dimensions and resolutions.

    Once I've checked for mobile visitors, I swap the template like so:

    try {
            Node currentNode = Node.GetCurrent();
            umbraco.template template = new umbraco.template(currentNode.template); /// get the template for the current node
            string tAlias = template.TemplateAlias.ToString();    
            Page.MasterPageFile = "/masterpages/Mobile/" + tAlias + "Mobile.master"; /// reformat the template alias for the mobile version - xMobile.master replaces x.master
            }

     My mobile template set follows a naming convention - Content.Master has the mobile version ContentMobile.Master, which allows me to grab the alias of the default template, append "Mobile" and away we go. Works well so far - the biggest plus for me is keeping the url the same for all visitors.

     

    cheers

    Nathan

  • Dmitriy Skudnov 39 posts 64 karma points
    Jul 25, 2012 @ 20:29
    Dmitriy Skudnov
    0

    @Mike Thank you for idea.

    I also was needed to have the same urls for desktop, mobile and table versions.

    I have ended up to put the code, which is doing "mobile detection" and switching template in default.aspx file like

    <%@ Page language="c#" Codebehind="default.aspx.cs" AutoEventWireup="True" Inherits="umbraco.UmbracoDefault" trace="true" validateRequest="false" %>
    <script language="c#" runat="server">
      protected override void OnPreInit(EventArgs e)
      {
       base.OnPreInit(e); //need to be before changin template 
    var md = new MobileDetector(); //my own class to detect version
        bool isMobile = md.DetectMobileLong();
        bool isTablet = md.DetectTierTablet();
       if (isTablet)
       {
        this.MasterPageFile = "/Masterpages/TabletVersionMaster.Master"; 
       }
       else if (isMobile)
       {
        this.MasterPageFile = "/Masterpages/MobileVersionMaster.Master"; 
       }
       else
       {
        this.MasterPageFile = "/Masterpages/DesktopVersionMaster.Master"; 
       }
    }
    </script>
  • Alex Lopez 8 posts 29 karma points
    Sep 19, 2012 @ 05:39
    Alex Lopez
    0

    Hi All,

    Could any of you guys post the complete solution instructions, I am pretty new here and like what you have done but I don't know what to do, I have just copied @Dimitry code to default.aspx and where do I @Mike's code?

    Basically I wand to detect mobile and then use the alttemplate.

    Thanks

  • Graham Carr 277 posts 389 karma points
    Oct 18, 2012 @ 09:49
    Graham Carr
    0

    Hi,

    Same as Alex, does anyone have a definitive solution they can post on how this is done in it's entirety, all of the information on this across the forums seems very fragmented. Would the code above work for a site that will multiple Alternate Templates??

    Graham

Please Sign in or register to post replies

Write your reply to:

Draft