Solved

using different stylesheet for IE browser   in the smarty

Posted on 2009-05-06
9
1,077 Views
Last Modified: 2013-11-10
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
Comment
Question by:mattibutt
  • 4
  • 3
  • 2
9 Comments
 
LVL 14

Expert Comment

by:EMB01
ID: 24319599
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
 
LVL 42

Expert Comment

by:David S.
ID: 24321961
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
 
LVL 11

Author Comment

by:mattibutt
ID: 24323549
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
 
LVL 42

Expert Comment

by:David S.
ID: 24323660
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 11

Author Comment

by:mattibutt
ID: 24323715
its not making a different
0
 
LVL 11

Author Comment

by:mattibutt
ID: 24323716
i dont think its picking the stylesheet
0
 
LVL 14

Accepted Solution

by:
EMB01 earned 300 total points
ID: 24328267
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
 
LVL 42

Assisted Solution

by:David S.
David S. earned 200 total points
ID: 24329911
> 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
 
LVL 11

Author Closing Comment

by:mattibutt
ID: 31578380
i still havent tried your smarty code but i am hopeful they will work
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
PHP Healthcheck 2 85
P tag not forcing line space 2 23
Making register page log you in after registration is complete. 2 13
manage footer size 4 7
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now