I've been reading and re-reading these "switch layout/template for mobile" forum posts for days now and finally got a setup that I like!
Basically, I'm only using ONE CSS file! It was getting confusing trying to style with a separate CSS file for mobile, so I just got rid of the mobile one, and made my regular one more versatile.
So how did I make it show up different? I too was REALLY interested in switching actual TEMPLATES not just the CSS. This is cause I wanted different info to show up on mobile than the online. (i.e.- Online I have a video slideshow. When viewed on mobile, it is just a <li> list of the videos with the title underneath).
In my Template, I put:
Code: Select all
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0;">
so that it would know to fit an iPhone (since this is really the only device I was interested in. You could easily adjust this to fit other browsers).
Still in my Template, I took my business to the {content} tag. I replaced my content tag with this:
Code: Select all
{if false !== $smarty.server.HTTP_USER_AGENT|lower|strpos:'iphone'}
{literal}
<__script__ type="text/javascript">
window.addEventListener("load", function() { setTimeout(loaded, 100) }, false);
function loaded() {
document.getElementById("page_wrapper").style.visibility = "visible";
window.scrollTo(0, 1); // pan to the bottom, hides the location bar
}
</__script>
{/literal}
<span class="mobile_content">{content block="Mobile Content"}</span>
{else}
<span class="regular_content">{content}</span>
{/if}
That JS just hides the addy bar on the iPhone. But as you see, I basically just have 2 content blocks in my template, and based on which browser you're on, it'll show one or the other!
So next, on to editing my page... Managing two copies of content is NOT what I'm wanting to do.. I want one central location of content that I can change. Then it hit me... one place I have the ability to switch templates, is within modules! I'll work with ListIt in this example.
So in my MAIN Content block I put:
Code: Select all
{ListIt2 summarytemplate='My ListIt Template'}
Then in my MOBILE Content block I put:
Code: Select all
{ListIt2 summarytemplate='My Mobile ListIt Template'}
And that did the trick! Now you just need to go into your ListIt templates and build the 2 different templates how you want them to look! Then if someone is on their iPhone, it will show your ListIt Mobile Template. It works beautifully for me!
You can do this with any module that has the ability to set the template. Now your customer never has to look at the PAGES tab, but will just go to the modules they need to update, and it will magically switch the layout based on the device!
Give it a shot! It worked great for me so I thought I would share!