Page 1 of 1
php in css?
Posted: Thu Feb 17, 2005 2:00 pm
by shiznatix
I have style.css and I use it through my whole site, but I want to be able to change colors and table sizes in the style sheet through a admin section. Now how should I go about doing this? Would it be best to make it all in a db and save the css file as style.php and have the values of the colors and widths as fields in the database that can be updated or should i try to directly write to the file. Also, is it even possible to make a css sheet with variables like that? Im not quite sure how I should go about doing this so any ideas would be great.
Posted: Thu Feb 17, 2005 2:09 pm
by zylinder
Write a good Parser. Send the output to a HTML Form. Edit and Save the file. The database would contain to many fields. You have to name them all manualy.
I would write a parser.
Posted: Thu Feb 17, 2005 2:15 pm
by s.dot
It is very possible to put PHP fields in CSS
For example, here is my CSS for a portion of my site.
Code: Select all
<style type="text/css">
a:link { font-weight: bold; color: #<? if ($rowї"linktextcolor"]) { echo "$rowїlinktextcolor]"; } else { echo "000000"; } ?>; text-decoration: none; font-size: 13px; font-family: times new roman, arial; }
a:visited { font-weight: bold; color: #<? if ($rowї"linktextcolor"]) { echo "$rowїlinktextcolor]"; } else { echo "000000"; } ?>; text-decoration: none; font-size: 13px; font-family: times new roman, arial; }
a:hover { font-weight: bold; color: #<? if ($rowї"linktextcolor"]) { echo "$rowїlinktextcolor]"; } else { echo "000000"; } ?>; text-decoration: underline; font-size: 13px; font-family: times new roman, arial; }
a:active { font-weight: bold; color: #<? if ($rowї"linktextcolor"]) { echo "$rowїlinktextcolor]"; } else { echo "000000"; } ?>; text-decoration: none; font-size: 13px; font-family: times new roman, arial; }
body { font-size: 15px; color: #<? if ($rowї"textcolor"]) { echo "$rowїtextcolor]"; } else { echo "000000"; } ?>; font-family: times new roman, arial; }
Hope this helps you.
Posted: Thu Feb 17, 2005 2:22 pm
by shiznatix
Any links to a tutorial on how to code a parser? I searched google but I didn't come across anything good.
Posted: Thu Feb 17, 2005 2:30 pm
by zylinder
http://www.selfphp.com/
Look for the functions
Then try to find a pattern in your css code
Posted: Thu Feb 17, 2005 4:27 pm
by shiznatix
Yes I could just rewrite the file but thats getting a little complicated and when I have somthing like
Code: Select all
#forums, table.posts, #profile { border-collapse: collapse; font: .9em Verdana, Arial, sans-serif; width: 100%; }
#forums, #forums th, #forums td { border: 1px solid #805E40; }
#forums th, table.posts th { background: #E6BD73; font-size: .9em; }
#forums th { color:#000; padding: .25em; }
#forums td, table.posts td { background: #FFE3BF; }
#forums td { padding: .5em; }
#forums .category { background: #FFD280; color: #000; font-weight: bold; padding: .3em; }
#forums .type { padding: 0 .25em 0 .3em; }
#forums .name { text-align: left; width: 100%; }
#forums .author, #forums .topics, #forums .posts { text-align: center; }
#forums .author { white-space: nowrap; }
#forums td.lastpost, #forums td.lastpostlink { font-size: 0.8em; }
#forums th.lastpost, #forums td.lastpost { white-space: nowrap; }
#forums span.desc { color: #899; font-size: 0.9em; }
#forums span.modlinks { float: right; font-size: 0.75em; }
#forums span.modlinks a { color: #344; text-decoration: none; }
#forums span.modlinks a:hover { background: none; color: #566; }
#forums span.authortitle { font-size: 0.9em; color: #BF9D60; }
#forums .postauthor { width: 13em; }
#forums td.postauthor { padding-bottom: 1em; }
#forums td.postauthor, #forums td.posttext { vertical-align: top; }
I want to be able to use a db to have multiple skins that i can just change with a simple form but any ideas on how to do this all without having extream amounts of fields in my db table because i cant think of any other way except making each color and text decoration a seperate field? using another db would organize it a lot but that is not a option. any sugestions?
Posted: Thu Feb 17, 2005 4:39 pm
by s.dot
review my code above again. You'd only need 1 field in your database that corresponds to each css line. In your case you'd need 21 fields.
After you set that, you could easily set up a form to switch between skins with 1 click.
Posted: Thu Feb 17, 2005 4:41 pm
by shiznatix
that was only a snippet of the css, going by your way it would end up being about 100 fields, this would cause quite some overhead being loaded every time you load a page, or am i wrong?
Posted: Thu Feb 17, 2005 4:44 pm
by s.dot
wouldn't cause an overhead unless you deleted/appended records to it all the time, which in your case, once the fields are set you won't have to worry about any overhead problems, unless you delete skins in the future.
Posted: Thu Feb 17, 2005 5:50 pm
by shiznatix
well the skins would be deleted/created every so often but it wouldnt be somthing that happened often, maybe total of 10 times each in about a year? but this wont cause pages to load slowly or anything if i have to query 100 fields in a table every time someone clicks any link on the site?
Posted: Thu Feb 17, 2005 6:25 pm
by feyd
I don't believe a selection query affects overhead, only update/delete/insertions would.. and all you have to do to "fix" it is an optimize query..

Posted: Thu Feb 17, 2005 8:20 pm
by shiznatix
this is getting extream already, is there a easier way to have multiple templates than this!?
Posted: Thu Feb 17, 2005 8:34 pm
by feyd
you could do a generic of template_id, css_id, css_string.. but why not just have seperate files so you don't have to perform a database query?
Posted: Thu Feb 17, 2005 9:13 pm
by shiznatix
well i kinda want to be able to create themes, but i think i got a better idea