• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1143
  • Last Modified:

using different stylesheet for IE browser in the smarty

i have a style sheet which uses the following code for css
<link href="{$smarty.const._URL}/templates/{$template_dir}/style.css" rel="stylesheet" type="text/css" />

i want to create seperate style sheet for IE
<!--[if  IE 6]>
<link rel="stylesheet" type="text/css" href=Iestyle.css">
<![endif]-->
it doesnt i dont know how i can do this in smarty
0
mattibutt
Asked:
mattibutt
  • 4
  • 3
  • 2
2 Solutions
 
EMB01Commented:
You may want to consider this, a free plugin for the SmartyPHP templating engine that aims to provide multibrowser CSS-support. Ergo, with it you should be able to integrate multiple stylesheets:
http://phpinsider.com/smarty-forum/viewtopic.php?t=13635
0
 
David S.Commented:
Conditional comments are far superior to user-agent-string sniffing.

Can't you just do this?
<link href="{$smarty.const._URL}/templates/{$template_dir}/style.css" rel="stylesheet" type="text/css" />
<!--[if  IE 6]>
<link rel="stylesheet" type="text/css" href="{$smarty.const._URL}/templates/{$template_dir}/Iestyle.css" />
<![endif]-->

Open in new window

0
 
mattibuttAuthor Commented:
hi guys
thanks for your reply, EMB01i see the plugin question is how do i configure it.
Kravimir i have tried that but thing is i dont have IE 6 if i want to use the same statement for IE7 how do i use it?
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
David S.Commented:
If you want to use it for IE7 and older versions, then you can do this:
<link href="{$smarty.const._URL}/templates/{$template_dir}/style.css" rel="stylesheet" type="text/css" />
<!--[if lte IE 7]>
<link rel="stylesheet" type="text/css" href="{$smarty.const._URL}/templates/{$template_dir}/Iestyle.css" />
<![endif]-->

Open in new window

0
 
mattibuttAuthor Commented:
its not making a different
0
 
mattibuttAuthor Commented:
i dont think its picking the stylesheet
0
 
EMB01Commented:
The instructions for the plugin are at the address posted above. All you do is create the file with the attached code and include it into your PHP page. Then, in your PHP page, just replace your HTML body tag with this:
<body class="{insert name="browser_body_style"}">

Good luck!
<?php 
/** 
 * Smarty plugin 
 * @package Smarty 
 * @subpackage ewtplugins 
 */ 
 
/* 
 * Smarty {browser_body_style} insert plugin 
 * 
 * File:     insert.browser_body_style.php<br> 
 * Type:     insert 
 * Name:     browser_body_style 
 * Date:    July 16, 2008 
 * Purpose:  generate browser/os-specific class names for the body tag to facilitate browser-specific CSS 
 * @author   Jason Habbley <jason at edgeworkstech dot com> 
 * @version  0.2 
 */ 
 
 
function smarty_insert_browser_body_style($params, &$smarty) 
{ 
 
    $browser = array ("IE","OPERA","MOZILLA","NETSCAPE","FIREFOX","SAFARI"); 
    $os = array ("WIN","MAC"); 
    $info['browser'] = "OTHER"; 
    $info['os'] = "OTHER"; 
  
    foreach ($browser as $parent) 
        { 
        $s = strpos(strtoupper($_SERVER['HTTP_USER_AGENT']), $parent); 
        $f = $s + strlen($parent); 
        $version = substr($_SERVER['HTTP_USER_AGENT'], $f, 5); 
        $version = preg_replace('/[^0-9,.]/','',$version); 
        if ($s) 
            { 
            $info['browser'] = $parent; 
            $info['version'] = $version; 
            } 
        } 
  
    foreach ($os as $val) 
    { 
        if (eregi($val,strtoupper($_SERVER['HTTP_USER_AGENT']))) $info['os'] = $val; 
    } 
    
   $output = array(); 
   //os_browser_version 
   $output[] = join("_", array($info['os'], $info['browser'], (int)$info['version'])); 
   //os_browser 
   $output[] = join("_", array($info['os'], $info['browser'])); 
   //browser_version 
   $output[] = join("_", array($info['browser'], (int)$info['version'])); 
   //os 
   $output[] = $info['os']; 
   //browser 
   $output[] = $info['browser']; 
 
   return strtolower(join(" ", $output)); 
} 
?>

Open in new window

0
 
David S.Commented:
> i dont think its picking the stylesheet

Perhaps I should mention that IE7 will use both stylesheets. The second one will override the first one where there are conflicts though.

Do you have a live page that we could look at?
0
 
mattibuttAuthor Commented:
i still havent tried your smarty code but i am hopeful they will work
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now