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?
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.
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();
}
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.
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.
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.
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 ;)
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.
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.
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??
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:
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.
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.
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
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.
:-)
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
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 ;)
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:
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
@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
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
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
is working on a reply...