Jump to content

Page-specific CSS


LOLZcat

Recommended Posts

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 :P). 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. :P

 

Thanks. :)

Link to comment
https://forums.phpfreaks.com/topic/200224-page-specific-css/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.