Complex CSS issue.
I am currently working on a site that is Based on PHP and is using smartys. It is designed to be completely modular. Parts will be completely interchangeable. There are around 50 different parts. Each one is a .tpl.
Sense there are so many different parts that have almost as many different looks I need to define them all as IDs in the CSS. Thus making each section quickly and easily editable.
I have a core CSS file that defines the basic setting to the site. Some of the most common sections/IDs are defined in that CSS as well. The problem is, I would like to separate out the different IDs into separate CSS files that will be located in a CSS directory. My reason for wanting to do this is that for quick loading. I only want the "needed" files to load.
Here is the question...
I know that the CSS files need to be defined in the head of the page itself. I want to make it so that if a specific .tpl file is called upon that it will load the corresponding CSS file for that section. Is there a way to do this. I have thought of some options but nothing that I like.
I know that you must be thinking.. Why dont you just put it all in one CSS file and leave it at that. Here is my answer: The CORE CSS file is only half complete and it is quite large. I think that that is a bit excessive and am trying to keep the load time down. The second reason is that I want to make it VERY easy to edit each sections CSS/looks. If you know what section you want to change you find that files CSS and edit it directly (no searching) and your done.
Just so you know the project is a POS/Inventory management system for motorcycle shops.
Thanks
Suzanne posted this at 22:11 — 26th February 2004.
She has: 5,507 posts
Joined: Feb 2000
<?php
<link type=\"text/css\" rel=\"stylesheet\" href=\"=$sectionName;.css\" />
?>
Dorn posted this at 03:22 — 27th February 2004.
They have: 42 posts
Joined: Jul 2001
can that be done for multiple sections at once?
Perhaps I do not fully understand what you are saying.
Where can I find out more?
THank you for the help.
Suzanne posted this at 06:34 — 27th February 2004.
She has: 5,507 posts
Joined: Feb 2000
Say your header has this:
<link type="text/css" rel="stylesheet" href="mainstyles.css" />
Then you can add some conditional scripting to your header:
<?php
<link type=\"text/css\" rel=\"stylesheet\" href=\"mainstyles.css\" />
switch($section) {
case $section:
echo \"<link type=\\"text/css\\" rel=\\"stylesheet\\" href=\\"$section.css\\" />\";
break;
default:
echo \"<link type=\\"text/css\\" rel=\\"stylesheet\\" href=\\"defaultsection.css\\" />\";
break;
?>
So name all your section .css files so you can code to a keyword and you can set the variable in the header or however you determine which section you're in (page request, folder, whatever).
Or alternatively have something like
<?php
$section = \"thissectionname\";
?>
At the very top of all your documents before the header is included and this in your header:
<?php
<link type=\"text/css\" rel=\"stylesheet\" href=\"mainstyles.css\" />
<link type=\"text/css\" rel=\"stylesheet\" href=\"=$section;.css\" />
?>
It probably depends on your .tpl though.
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.