Here’s a recipe which will allow you to use the same address for both mobile and normal sites. If the request looks like it is coming from a mobile device then the mobile template is used, else the normal template is used. I have something similar (but not exactly the same) implemented. The following is untested, but should work.
To implement this, first you need two chunks. NormalTpl contains your normal template, and MobileTpl contains your mobile template. You should then create a real template for your page that looks like this:
{{NormalTpl}}#####{{MobileTpl}}
Next you need some php code that will analyse the HTTP headers on each page request and decide whether it’s a mobile device that has requested the page or not. You could use the
detect mobile browsers script for example. That code should be executed every time the page is requested, so it needs to be called on the OnWebPagePrerender event.
So, the next step is to create a new plugin. Lets call it MobileSnifferTemplateChooser. From the system events tab, select the OnWebPagePrerender event. Within the General tab you need to do three things.
1. Include your favourite php mobile detection script. Save the result in a variable, called, for example, $isMobileDevice.
2. Include some code like the following, which will analyse your document content, and pick out the two templates.
list($normalTpl,$mobileTpl) = explode('#####', $modx->documentOutput);
3. Choose the correct template
if ( $isMobileDevice )
{
$modx->documentOutput = $mobileTpl;
}
else
{
$modx->documentOutput = $normalTpl;
}
That should be it. I’d love to hear if you tried it and if it works for you.