PDA

View Full Version : User Agent Detection at the template level


Barrett
06-26-08, 03:09 PM
What would it take to get the browser user agent value and be able to use it in a conditional in template like a Cat or Prod page ?

Example:

<mvt:item name="html_profile" />
<html>
<head>
<title>&mvt:category:name;</title>
<base href="&mvt:global:basehref;">
<mvt:item name="prodctgy_meta" param="ctgy" />
<mvt:item name="head" param="head_tag" />
</head>
<mvt:item name="body">
<div id="global_header"><mvt:item name="hdft" param="global_header" /></div>
<div id="header"><mvt:item name="hdft" param="header" /></div>
<div id="navbar"><mvt:item name="navbar" /></div>

<mvt:if [Internet Explore 6]>
process and display all this template code
<mvt:if [Internet Explore 7]>
process and display all this template code
ELSE
process and display all this template code
that works properly in every other decent browser llike FireFox 3 and Safari 3
</mvt:if>

PCINET - Andreas
06-26-08, 04:44 PM
There is a lot of JavaScript on the web which tests for the browser. All you need to do is use this code and add the template code in the right sections.

wcw
06-26-08, 04:49 PM
The template gets parsed on the server before it hands the page to the browser. It is at the browser level that those values can be known with javascript. Unfortunately, that is too late. When the page was parsed, those values were all blank.

Kent Multer
06-26-08, 05:03 PM
Isn't there a system variable for that? I think you can use s.http_user_agent in the conditional.

PCINET - Andreas
06-26-08, 05:08 PM
Hey Ken,

You are right, I saw some times ago this and that's the solution:

http://extranet.mivamerchant.com/forums/archive/index.php/t-10975.html

Biffy
06-26-08, 09:47 PM
I use htaccess for user-agent detection and then serve up different templates and CSS. It will even handle different sub-versions of the same browser, Safari 2.0 and 2.1 for instance.

So, you get a call for a template and you redirect 20 browsers to 20 different templates. Or send 'em all to the same template but use 20 different CSS stylesheets.

I posted this script here on the forums somewhere. A little bit of search oughta turn it up.

Leanne
06-30-08, 07:37 AM
It's here (http://extranet.mivamerchant.com/forums/showthread.php?p=72591#post72591). I bookmarked it, because it's too cool. I played with it some on a site revamp I'm doing, and it came in very handy.