LOLZcat Posted April 29, 2010 Share Posted April 29, 2010 Hello. I'm having trouble with a code to get page specific CSS. I'm trying to learn PHP templating, so I'm testing various things. Basically, I've set up a bare-bones templating system where we just use the "page=" attribute to grab the content of the page, eg: if (file_exists('./includes/' . $_GET['page'] . '.php')) require_once('./includes/' . $_GET['page'] . '.php'); elseif (!isset($_GET['page']) || !file_exists('./includes/' . $_GET['page'] . '.php')) require_once('./includes/home.php'); which has worked alright for me. Of course we have stuff above/below the content to template it. But, I'm trying to be able to add to my CSS file for each individual page (to avoid calling extra file size... yeah, I'm paranoid with that stuff ). Here is what is not working for me... my style.php file is: <?php header('Content-type: text/css'); global $page; $page['add_css'] = isset($page['add_css']) ? $page['add_css'] : ''; echo 'My standard CSS for each page here...' . $page['add_css'] . ''; ?> and it's called up like this in the template: <link rel="stylesheet" href="/style.php" /> I attempted to add on to no avail (this was in one of the specific pages): global $page; $page['add_css'] = 'ul.nolist { list-style-type:none }'; I am a complete templating n00b, so please don't hurt me. Thanks. Link to comment https://forums.phpfreaks.com/topic/200224-page-specific-css/ Share on other sites More sharing options...
teamatomic Posted April 29, 2010 Share Posted April 29, 2010 I would set it in the header. Include the general stylesheet then check for a page specific stylesheet, if it exists then include it. HTH Teamatomic Link to comment https://forums.phpfreaks.com/topic/200224-page-specific-css/#findComment-1050747 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.