Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.
- Index
- » Chameleon / ChameleonLite
- » ChameleonLite
- » template change depending on user...
template change depending on user browser
template change depending on user browser
Hi
i have just found this Valuable component (MetaTemplate free edition).
how can i write a rule to show different templates to different users accroding to their browser? e.g. IE6 -->template 1, IE7 -->template 2, FireFox2 -->template 3, firefox 3 -->template 4
thanks a lot
ali reza
22-Jun-10 04:14:05
Re: template change depending on user browser
Hi baambooli,
you can actually adapt some code that was written for MetaMod. The rules are very similar. Check out this page:
http://www.metamodpro.com/metamod/recip … -detection
The difference is what you "return" in the "if" statements. In MetaMod, you return a module id number. In MetaTemplate, you need to return a template name.
So your rule might look like this:
Code:
$UA = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
$CH = strstr($UA, 'Chrome/') ? true : false;
$CHV = $CH ? preg_match('#Chrome/([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)#',
$UA, $matches) : false;
$CHV = $CHV ? $matches[1] : false;
$IPD = strstr($UA, 'iPad;') ? true : false;
$IP = strstr($UA, 'iPhone') ? true : false;
$SF = !$CH && strstr($UA, 'Safari') ? true : false;
$OP = strstr($UA, 'Opera') ? true : false;
$OPV = $OP ? preg_split('/opera\//i', $UA) : false;
$OPV = $OPV ? floatval($OPV[1]) : false;
$FF = strstr($UA, 'Firefox') ? true : false;
$FFV = $FF ? preg_split('/firefox\//i', $UA) : false;
$FFV = $FFV ? floatval($FFV[1]) : false;
$IE = strstr($UA, 'MSIE') ? true : false;
$IEV = $IE ? preg_split('/msie/i', $UA) : false;
$IEV = $IEV ? floatval($IEV[1]) : false;
// customise the template names as appropriate for your site
if ($IE and $IEV >= 7) return "template1"; // any version of IE greater or equal to 7
if ($IE and $IEV >= 6) return "template2"; // any version of IE greater or equal to 6
if ($IE) return "template3"; // any version (at all) of IE
if ($OP) return "template4"; // any version of Opera
if ($FF) return "template5"; // any version of Firefox
if ($IP) return "template6"; // any version of iPhone
if ($IPD) return "template7"; // any version of iPad
if ($SF) return "template8"; // any version of Safari (excl Chrome but incl iPhone and iPad)
if ($CH) return "template9"; // any version of Google Chrome
if ($CHV == "0.2.149.27") return "template10"; /* specific Chrome version */
Hope that helps,
Stephen
Re: template change depending on user browser
Actually this does more exactly what you asked for:
Code:
$UA = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
$FF = strstr($UA, 'Firefox') ? true : false;
$FFV = $FF ? preg_split('/firefox\//i', $UA) : false;
$FFV = $FFV ? floatval($FFV[1]) : false;
$IE = strstr($UA, 'MSIE') ? true : false;
$IEV = $IE ? preg_split('/msie/i', $UA) : false;
$IEV = $IEV ? floatval($IEV[1]) : false;
// customise the template names as appropriate for your site
if ($IE and (int)$IEV == 6) return "template1"; // IE v 6.x
if ($IE and (int)$IEV == 7) return "template2"; // IE v 7.x
if ($FF and (int)$FFV == 2) return "template3"; // FF v2.x
if ($FF and (int)$FFV == 3) return "template4"; // FF v3.x
- Index
- » Chameleon / ChameleonLite
- » ChameleonLite
- » template change depending on user...
Board Info
- Board Stats:
- Total Topics:
- 1689
- Total Polls:
- 6
- Total Posts:
- 5944
- Posts this week:
- 1
- User Info:
- Total Users:
- 7669
- Newest User:
- norton4568
- Members Online:
- 0
- Guests Online:
- 162
- Online:
- There are no members online
Forum Legend:
Topic
New
Locked
Sticky
Active
New/Active
New/Locked
New Sticky
Locked/Active
Active/Sticky
Sticky/Locked
Sticky/Active/Locked