Welcome Guest, Not a member yet? Register   Sign In
Problem loading CSS file with relative path
#13

[eluser]lenwood[/eluser]
I'll throw in my solution. I'm using 960 grid system for my project, and need page specific CSS files (admin pages vs external pages, for instance). All of my CSS is stored in a /CSS folder, which I've listed in my .htaccess file. I call three views for each page, header, page-name and footer. I got this from Coder320 here.

Controller:
Code:
function index() {
  $data['title'] = "This is my page title.";
  $data['descr'] = "This is my meta description.";
  $data['css'] = array('/CSS/reset.css', '/CSS/text.css', '/CSS/960.css');
  $this->load->view('header', $data);
  $this->load->view('page-name');
  $this->load->view('footer');

Header:
Code:
<html>
<head>
<title><?php echo $title;?></title>
<meta name="description" content="<?php echo $descr;?>" />
<?php
if(isset($css))
foreach($css as $file):
  echo '<link rel="stylesheet" type="text/css" media="all" href="'.$file.'" />'."\n";
endforeach;
?>
</head>
<body>

This renders as:
Code:
<html>
<head>
<title>This is my page title.</title>
<meta name="description" content="This is my meta description." />
<link rel="stylesheet" type="text/css" media="all" href="/CSS/reset.css" />
<link rel="stylesheet" type="text/css" media="all" href="/CSS/text.css" />
<link rel="stylesheet" type="text/css" media="all" href="/CSS/960.css" />
</head>
<body>

For page specific CSS, I just tack on one more CSS file in the array with those specific updates and it works beautifully.


Messages In This Thread
Problem loading CSS file with relative path - by El Forum - 04-09-2010, 02:29 PM
Problem loading CSS file with relative path - by El Forum - 04-09-2010, 05:32 PM
Problem loading CSS file with relative path - by El Forum - 04-10-2010, 12:35 AM
Problem loading CSS file with relative path - by El Forum - 04-10-2010, 01:25 AM
Problem loading CSS file with relative path - by El Forum - 04-10-2010, 02:27 AM
Problem loading CSS file with relative path - by El Forum - 04-10-2010, 02:50 AM
Problem loading CSS file with relative path - by El Forum - 04-26-2010, 01:50 AM
Problem loading CSS file with relative path - by El Forum - 04-26-2010, 01:55 AM
Problem loading CSS file with relative path - by El Forum - 04-26-2010, 02:02 AM
Problem loading CSS file with relative path - by El Forum - 04-26-2010, 04:10 AM
Problem loading CSS file with relative path - by El Forum - 04-26-2010, 04:30 AM
Problem loading CSS file with relative path - by El Forum - 04-26-2010, 04:35 AM
Problem loading CSS file with relative path - by El Forum - 04-26-2010, 10:26 AM



Theme © iAndrew 2016 - Forum software by © MyBB