by
KK » Fri Feb 15, 2013 7:57 pm
Fine.
Assuming we go with
http://code.google.com/p/php-mobile-detect/ (though the jQuery method will also work) to detect if the visitor should be served the mobile version, following (IMHO) should be the cleanest approach for creating two versions of the same site -
Continuing with the example of 'news.php', this is what we do (the approach will remain identical for every single template of the site) -
1. 'news.php' remains the
single point of entry for both versions of the site.
2. It defines editable regions the normal way ..
3. .. but does not output anything at all by itself.
4. It uses the' php-mobile-detect' PHP class mentioned above to detect if the visitor requires a mobile version and sets a Couch variable (say 'is_mobile') accordingly.
5. Next, depending on the value of the 'is_mobile' variable, the template embeds either the 'normal' version of the news or the 'mobile 'version.
- Code: Select all
<?php require_once 'couch/cms.php'; ?>
<cms:template clonable='1'>
.. define all editable regions ..
</cms:template>
<cms:php>
include 'Mobile_Detect.php';
$detect = new Mobile_Detect();
if ($detect->isMobile()) {
// Any mobile device.
global $CTX;
$CTX->set( 'is_mobile', '1' );
}
</cms:php>
<cms:if is_mobile >
<cms:embed 'mobile/news.htm' />
<cms:else />
<cms:embed 'normal/news.htm' />
</cms:if>
<?php COUCH::invoke(); ?>
Basically, with this method, the two complete versions of your site now reside completely in the 'normal' and 'mobile' subfolders of the 'snippets' folder.
Hope I was able to explain myself.
Do let me know what you make of it.
EDITED: Code rectified