FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Parsing .css files with php: Cons?
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
Parsing .css files with php: Cons? [message #176676] Mon, 16 January 2012 21:36 Go to next message
J. Frank Parnell is currently offline  J. Frank Parnell
Messages: 12
Registered: January 2012
Karma: 0
Junior Member
given: I know about @import and cascading styles, etc etc.

Is is cool to parse .css files with php? Like I may want to include()
sections into an overall .css. Or i may want to do like color:#<?php
echo $thecolor; ?>. That kind of stuff.

I guess there might be a little more overhead, but what's a few .css
files within a whole cms like wordpress? I'm just looking for gotchas
and unforseen problems.

thanks,
j
Re: Parsing .css files with php: Cons? [message #176683 is a reply to message #176676] Tue, 17 January 2012 10:42 Go to previous messageGo to next message
Erwin Moller is currently offline  Erwin Moller
Messages: 228
Registered: September 2010
Karma: 0
Senior Member
On 1/16/2012 10:36 PM, J. Frank Parnell wrote:
> given: I know about @import and cascading styles, etc etc.
>
> Is is cool to parse .css files with php? Like I may want to include()
> sections into an overall .css. Or i may want to do like color:#<?php
> echo $thecolor; ?>. That kind of stuff.
>
> I guess there might be a little more overhead, but what's a few .css
> files within a whole cms like wordpress? I'm just looking for gotchas
> and unforseen problems.
>
> thanks,
> j

Hi,

It is possible, but I prefer making multiple stylesheets.
Make the included stylesheet conditional.
eg:

<?php
$usedstylesheet = ($test?"mycss/ver_abc.css":"mycss/ver_123.css");
$>
<link type="text/css" rel="stylesheet" media="screen" charset="utf-8"
href="http://www.example.com/<?php echo $usedstylesheet; ?>">

That way you have no PHP defining your stylesheet. That will make
webdesigners who have to modify it later happy. ;-)

Regards,
Erwin Moller


--
"That which can be asserted without evidence, can be dismissed without
evidence."
-- Christopher Hitchens
Re: Parsing .css files with php: Cons? [message #176684 is a reply to message #176676] Tue, 17 January 2012 12:31 Go to previous messageGo to next message
alvaro.NOSPAMTHANX is currently offline  alvaro.NOSPAMTHANX
Messages: 277
Registered: September 2010
Karma: 0
Senior Member
El 16/01/2012 22:36, J. Frank Parnell escribió/wrote:
> given: I know about @import and cascading styles, etc etc.
>
> Is is cool to parse .css files with php? Like I may want to include()
> sections into an overall .css. Or i may want to do like color:#<?php
> echo $thecolor; ?>. That kind of stuff.
>
> I guess there might be a little more overhead, but what's a few .css
> files within a whole cms like wordpress? I'm just looking for gotchas
> and unforseen problems.

You might be interested in one of the existing CSS preprocessors, such
as SASS or LESS. It's basically the idea you are describing, except that:

- CSS is generated once (not for every request).
- The code is already written (and not necessarily in PHP).


--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--
Re: Parsing .css files with php: Cons? [message #176685 is a reply to message #176676] Tue, 17 January 2012 12:32 Go to previous messageGo to next message
Captain Paralytic is currently offline  Captain Paralytic
Messages: 204
Registered: September 2010
Karma: 0
Senior Member
On Jan 16, 9:36 pm, "J. Frank Parnell" <jugl...@gmail.com> wrote:
> given: I know about @import and cascading styles, etc etc.
>
> Is is cool to parse .css files with php?  Like I may want to include()
> sections into an overall .css.  Or i may want to do like color:#<?php
> echo $thecolor; ?>.  That kind of stuff.
>
> I guess there might be a little more overhead, but what's a few .css
> files within a whole cms like wordpress?  I'm just looking for gotchas
> and unforseen problems.
>
> thanks,
> j

I suspect a more normal way to do this would be to use php files to
generate your css rather like you would use them to generate your
html. So in the html sent to the browser you would have:
<link type="text/css" rel="stylesheet" media="screen" charset="utf-8"
href="http://www.example.com/dynamic_css.php?anyparms">

and dynamic_css.php would return the css.
Re: Parsing .css files with php: Cons? [message #176719 is a reply to message #176685] Thu, 19 January 2012 20:45 Go to previous messageGo to next message
J. Frank Parnell is currently offline  J. Frank Parnell
Messages: 12
Registered: January 2012
Karma: 0
Junior Member
On Jan 17, 4:32 am, Captain Paralytic <paul_laut...@yahoo.com> wrote:
> On Jan 16, 9:36 pm, "J. Frank Parnell" <jugl...@gmail.com> wrote:
>
>> given: I know about @import and cascading styles, etc etc.
>
>> Is is cool to parse .css files with php?  Like I may want to include()
>> sections into an overall .css.  Or i may want to do like color:#<?php
>> echo $thecolor; ?>.  That kind of stuff.
>
>> I guess there might be a little more overhead, but what's a few .css
>> files within a whole cms like wordpress?  I'm just looking for gotchas
>> and unforseen problems.
>
>> thanks,
>> j
>
> I suspect a more normal way to do this would be to use php files to
> generate your css rather like you would use them to generate your
> html. So in the html sent to the browser you would have:
> <link type="text/css" rel="stylesheet" media="screen" charset="utf-8"
> href="http://www.example.com/dynamic_css.php?anyparms">
>
> and dynamic_css.php would return the css.

ok, yeah, this would be my preferred way of the three suggestions
(thanks all!). Then, i suppose, I would need to set proper headers in
the php file? or maybe it would come thru fine by itself?
Re: Parsing .css files with php: Cons? [message #176725 is a reply to message #176719] Fri, 20 January 2012 10:07 Go to previous messageGo to next message
Captain Paralytic is currently offline  Captain Paralytic
Messages: 204
Registered: September 2010
Karma: 0
Senior Member
On Jan 19, 8:45 pm, "J. Frank Parnell" <jugl...@gmail.com> wrote:
> On Jan 17, 4:32 am, Captain Paralytic <paul_laut...@yahoo.com> wrote:
>
>
>
>
>
>
>
>
>
>> On Jan 16, 9:36 pm, "J. Frank Parnell" <jugl...@gmail.com> wrote:
>
>>> given: I know about @import and cascading styles, etc etc.
>
>>> Is is cool to parse .css files with php?  Like I may want to include()
>>> sections into an overall .css.  Or i may want to do like color:#<?php
>>> echo $thecolor; ?>.  That kind of stuff.
>
>>> I guess there might be a little more overhead, but what's a few .css
>>> files within a whole cms like wordpress?  I'm just looking for gotchas
>>> and unforseen problems.
>
>>> thanks,
>>> j
>
>> I suspect a more normal way to do this would be to use php files to
>> generate your css rather like you would use them to generate your
>> html. So in the html sent to the browser you would have:
>> <link type="text/css" rel="stylesheet" media="screen" charset="utf-8"
>> href="http://www.example.com/dynamic_css.php?anyparms">
>
>> and dynamic_css.php would return the css.
>
> ok, yeah, this would be my preferred way of the three suggestions
> (thanks all!).  Then, i suppose, I would need to set proper headers in
> the php file?  or maybe it would come thru fine by itself?

The latter
Re: Parsing .css files with php: Cons? [message #176726 is a reply to message #176725] Fri, 20 January 2012 10:25 Go to previous messageGo to next message
Michael Fesser is currently offline  Michael Fesser
Messages: 215
Registered: September 2010
Karma: 0
Senior Member
.oO(Captain Paralytic)

> On Jan 19, 8:45 pm, "J. Frank Parnell" <jugl...@gmail.com> wrote:
>> On Jan 17, 4:32 am, Captain Paralytic <paul_laut...@yahoo.com> wrote:
>>> I suspect a more normal way to do this would be to use php files to
>>> generate your css rather like you would use them to generate your
>>> html. So in the html sent to the browser you would have:
>>> <link type="text/css" rel="stylesheet" media="screen" charset="utf-8"
>>> href="http://www.example.com/dynamic_css.php?anyparms">
>>
>>> and dynamic_css.php would return the css.
>>
>> ok, yeah, this would be my preferred way of the three suggestions
>> (thanks all!).  Then, i suppose, I would need to set proper headers in
>> the php file?  or maybe it would come thru fine by itself?
>
> The latter

No. You have to explicitly send the correct header or some browsers
might ignore the CSS. For example

header('Content-Type: text/css; charset=UTF-8')

Micha

--
http://mfesser.de/blickwinkel
Re: Parsing .css files with php: Cons? [message #176735 is a reply to message #176726] Fri, 20 January 2012 13:33 Go to previous messageGo to next message
Captain Paralytic is currently offline  Captain Paralytic
Messages: 204
Registered: September 2010
Karma: 0
Senior Member
On Jan 20, 10:25 am, Michael Fesser <neti...@gmx.de> wrote:
> .oO(Captain Paralytic)
>
>> On Jan 19, 8:45 pm, "J. Frank Parnell" <jugl...@gmail.com> wrote:
>>> On Jan 17, 4:32 am, Captain Paralytic <paul_laut...@yahoo.com> wrote:
>>>> I suspect a more normal way to do this would be to use php files to
>>>> generate your css rather like you would use them to generate your
>>>> html. So in the html sent to the browser you would have:
>>>> <link type="text/css" rel="stylesheet" media="screen" charset="utf-8"
>>>> href="http://www.example.com/dynamic_css.php?anyparms">
>
>>>> and dynamic_css.php would return the css.
>
>>> ok, yeah, this would be my preferred way of the three suggestions
>>> (thanks all!).  Then, i suppose, I would need to set proper headers in
>>> the php file?  or maybe it would come thru fine by itself?
>
>> The latter
>
> No. You have to explicitly send the correct header or some browsers
> might ignore the CSS. For example
>
> header('Content-Type: text/css; charset=UTF-8')
>
> Micha
>
> --http://mfesser.de/blickwinkel

Oh OK. Any ideas which ones?
Re: Parsing .css files with php: Cons? [message #176737 is a reply to message #176735] Fri, 20 January 2012 14:05 Go to previous messageGo to next message
Michael Fesser is currently offline  Michael Fesser
Messages: 215
Registered: September 2010
Karma: 0
Senior Member
.oO(Captain Paralytic)

> On Jan 20, 10:25 am, Michael Fesser <neti...@gmx.de> wrote:
>> No. You have to explicitly send the correct header or some browsers
>> might ignore the CSS. For example
>>
>> header('Content-Type: text/css; charset=UTF-8')
>
> Oh OK. Any ideas which ones?

In the past Gecko browsers (i.e. Firefox) were a bit picky about the
correct CSS content type. If the file wasn't delivered as text/css, it
was ignored.

Micha

--
http://mfesser.de/blickwinkel
Re: Parsing .css files with php: Cons? [message #176743 is a reply to message #176737] Sat, 21 January 2012 01:50 Go to previous messageGo to next message
Chuck Anderson is currently offline  Chuck Anderson
Messages: 63
Registered: September 2010
Karma: 0
Member
Michael Fesser wrote:
> .oO(Captain Paralytic)
>
>
>> On Jan 20, 10:25 am, Michael Fesser <neti...@gmx.de> wrote:
>>
>>> No. You have to explicitly send the correct header or some browsers
>>> might ignore the CSS. For example
>>>
>>> header('Content-Type: text/css; charset=UTF-8')
>>>
>> Oh OK. Any ideas which ones?
>>
>
> In the past Gecko browsers (i.e. Firefox) were a bit picky about the
> correct CSS content type. If the file wasn't delivered as text/css, it
> was ignored.
>
> Micha

I have successfully used:
header("Content-type: text/css");

After implementing a php based style sheet a couple of different times
it seemed wasteful, and a bit of a kludge. If the style sheet is
ultimately static, it is wasteful to keep generating one every time it
is used. Now I use a php script to generate the style sheet file for me.
If I want to make changes I edit the php based file (or any included
definition files, e.g., colors.php) and run it.

--
*****************************
Chuck Anderson • Boulder, CO
http://cycletourist.com
Turn Off, Tune Out, Drop In
*****************************
Re: Parsing .css files with php: Cons? [message #176744 is a reply to message #176743] Sat, 21 January 2012 07:10 Go to previous messageGo to next message
J.O. Aho is currently offline  J.O. Aho
Messages: 194
Registered: September 2010
Karma: 0
Senior Member
Chuck Anderson wrote:
> Michael Fesser wrote:
>> .oO(Captain Paralytic)
>>
>>> On Jan 20, 10:25 am, Michael Fesser <neti...@gmx.de> wrote:
>>>> No. You have to explicitly send the correct header or some browsers
>>>> might ignore the CSS. For example
>>>>
>>>> header('Content-Type: text/css; charset=UTF-8')
>>> Oh OK. Any ideas which ones?
>>
>> In the past Gecko browsers (i.e. Firefox) were a bit picky about the
>> correct CSS content type. If the file wasn't delivered as text/css, it
>> was ignored.
>>
> I have successfully used:
> header("Content-type: text/css");
>
> After implementing a php based style sheet a couple of different times it
> seemed wasteful, and a bit of a kludge. If the style sheet is ultimately
> static, it is wasteful to keep generating one every time it is used. Now I use
> a php script to generate the style sheet file for me. If I want to make
> changes I edit the php based file (or any included definition files, e.g.,
> colors.php) and run it.
>

I have to say it feels quite much of extra work, writing the php script which
generates the css, as you need to edit the php file, then IMHO you can quite
easily edit a css instead. I could see a bit more point of your script if you
have a database as a backend, where you store the values and recreate the css
each time the values change.


--

//Aho
Re: Parsing .css files with php: Cons? [message #176746 is a reply to message #176744] Sat, 21 January 2012 19:31 Go to previous messageGo to next message
Chuck Anderson is currently offline  Chuck Anderson
Messages: 63
Registered: September 2010
Karma: 0
Member
J.O. Aho wrote:
> Chuck Anderson wrote:
>> Michael Fesser wrote:
>>> .oO(Captain Paralytic)
>>>
>>>> On Jan 20, 10:25 am, Michael Fesser <neti...@gmx.de> wrote:
>>>> > No. You have to explicitly send the correct header or some browsers
>>>> > might ignore the CSS. For example
>>>> >
>>>> > header('Content-Type: text/css; charset=UTF-8')
>>>> Oh OK. Any ideas which ones?
>>>
>>> In the past Gecko browsers (i.e. Firefox) were a bit picky about the
>>> correct CSS content type. If the file wasn't delivered as text/css, it
>>> was ignored.
>>>
>> I have successfully used:
>> header("Content-type: text/css");
>>
>> After implementing a php based style sheet a couple of different
>> times it
>> seemed wasteful, and a bit of a kludge. If the style sheet is ultimately
>> static, it is wasteful to keep generating one every time it is used.
>> Now I use
>> a php script to generate the style sheet file for me. If I want to make
>> changes I edit the php based file (or any included definition files,
>> e.g.,
>> colors.php) and run it.
>>
>
> I have to say it feels quite much of extra work, writing the php
> script which generates the css, as you need to edit the php file, then
> IMHO you can quite easily edit a css instead.

I edit one php file and then simply invoke it. There is very little
more "work."

In preparation, I write a script that opens a file for writing (the css
file) and then one long heredoc to create it's contents. This creates
an easily reusable system for very little extra work.

> I could see a bit more point of your script if you have a database as
> a backend, where you store the values and recreate the css each time
> the values change.

It's not a database, but I include color definitions from a separate php
file.

--
*****************************
Chuck Anderson • Boulder, CO
http://cycletourist.com
Turn Off, Tune Out, Drop In
*****************************
Re: Parsing .css files with php: Cons? [message #176747 is a reply to message #176746] Sat, 21 January 2012 20:53 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 1/21/2012 2:31 PM, Chuck Anderson wrote:
> J.O. Aho wrote:
>> Chuck Anderson wrote:
>>> Michael Fesser wrote:
>>>> .oO(Captain Paralytic)
>>>>
>>>> > On Jan 20, 10:25 am, Michael Fesser <neti...@gmx.de> wrote:
>>>> >> No. You have to explicitly send the correct header or some browsers
>>>> >> might ignore the CSS. For example
>>>> >>
>>>> >> header('Content-Type: text/css; charset=UTF-8')
>>>> > Oh OK. Any ideas which ones?
>>>>
>>>> In the past Gecko browsers (i.e. Firefox) were a bit picky about the
>>>> correct CSS content type. If the file wasn't delivered as text/css, it
>>>> was ignored.
>>>>
>>> I have successfully used:
>>> header("Content-type: text/css");
>>>
>>> After implementing a php based style sheet a couple of different
>>> times it
>>> seemed wasteful, and a bit of a kludge. If the style sheet is ultimately
>>> static, it is wasteful to keep generating one every time it is used.
>>> Now I use
>>> a php script to generate the style sheet file for me. If I want to make
>>> changes I edit the php based file (or any included definition files,
>>> e.g.,
>>> colors.php) and run it.
>>>
>>
>> I have to say it feels quite much of extra work, writing the php
>> script which generates the css, as you need to edit the php file, then
>> IMHO you can quite easily edit a css instead.
>
> I edit one php file and then simply invoke it. There is very little more
> "work."
>
> In preparation, I write a script that opens a file for writing (the css
> file) and then one long heredoc to create it's contents. This creates an
> easily reusable system for very little extra work.
>
>> I could see a bit more point of your script if you have a database as
>> a backend, where you store the values and recreate the css each time
>> the values change.
>
> It's not a database, but I include color definitions from a separate php
> file.
>

I agree with J.O. Seems overly complicated to have to edit a PHP file
which then generates the CSS. Much easier just to edit the CSS -
especially when you have syntax-sensitive editors for CSS available.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: Parsing .css files with php: Cons? [message #176748 is a reply to message #176747] Sat, 21 January 2012 21:22 Go to previous messageGo to next message
Michael Fesser is currently offline  Michael Fesser
Messages: 215
Registered: September 2010
Karma: 0
Senior Member
.oO(Jerry Stuckle)

> On 1/21/2012 2:31 PM, Chuck Anderson wrote:
>> J.O. Aho wrote:
>>>
>>> I have to say it feels quite much of extra work, writing the php
>>> script which generates the css, as you need to edit the php file, then
>>> IMHO you can quite easily edit a css instead.
>>
>> I edit one php file and then simply invoke it. There is very little more
>> "work."
>>
>> [...]
>
> I agree with J.O. Seems overly complicated to have to edit a PHP file
> which then generates the CSS. Much easier just to edit the CSS -
> especially when you have syntax-sensitive editors for CSS available.

The whole point of using PHP for creating the CSS is to avoid having to
edit a dozen places in the CSS to change some color for example. Instead
you make use of PHP and variables. Much simpler.

And if you still want a "static" CSS for performance reasons, you have
to preprocess it. Calling a script for doing this is not much work.
Dependent on the used IDE this could even be automated in the build and
upload process.

Micha

--
http://mfesser.de/blickwinkel
Re: Parsing .css files with php: Cons? [message #176749 is a reply to message #176748] Sat, 21 January 2012 21:37 Go to previous messageGo to next message
Beauregard T. Shagnas is currently offline  Beauregard T. Shagnas
Messages: 154
Registered: September 2010
Karma: 0
Senior Member
Michael Fesser wrote:

> The whole point of using PHP for creating the CSS is to avoid having to
> edit a dozen places in the CSS to change some color for example. Instead
> you make use of PHP and variables. Much simpler.

For one color, in a properly "optimized" CSS file, shouldn't there just
be one place there as well? That's the way mine are. I place all the
specific styling as one would normally expect: by elements, IDs and
classes, then end the file with all the color designators. Something like
this little sample:

body {
background: white; color: black;
}
id1, id2, class1, class2, class3, class4 {
color: blue;
}
p, li {
color: green;
}

Then of course just use an 'include' in the PHP code to the CSS file.

--
-bts
-This space for rent, but the price is high
Re: Parsing .css files with php: Cons? [message #176750 is a reply to message #176748] Sat, 21 January 2012 22:08 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 1/21/2012 4:22 PM, Michael Fesser wrote:
> .oO(Jerry Stuckle)
>
>> On 1/21/2012 2:31 PM, Chuck Anderson wrote:
>>> J.O. Aho wrote:
>>>>
>>>> I have to say it feels quite much of extra work, writing the php
>>>> script which generates the css, as you need to edit the php file, then
>>>> IMHO you can quite easily edit a css instead.
>>>
>>> I edit one php file and then simply invoke it. There is very little more
>>> "work."
>>>
>>> [...]
>>
>> I agree with J.O. Seems overly complicated to have to edit a PHP file
>> which then generates the CSS. Much easier just to edit the CSS -
>> especially when you have syntax-sensitive editors for CSS available.
>
> The whole point of using PHP for creating the CSS is to avoid having to
> edit a dozen places in the CSS to change some color for example. Instead
> you make use of PHP and variables. Much simpler.
>
> And if you still want a "static" CSS for performance reasons, you have
> to preprocess it. Calling a script for doing this is not much work.
> Dependent on the used IDE this could even be automated in the build and
> upload process.
>
> Micha
>

Create your .css properly and you don't need to do that.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: Parsing .css files with php: Cons? [message #176751 is a reply to message #176750] Sun, 22 January 2012 01:17 Go to previous messageGo to next message
Chuck Anderson is currently offline  Chuck Anderson
Messages: 63
Registered: September 2010
Karma: 0
Member
Jerry Stuckle wrote:
> On 1/21/2012 4:22 PM, Michael Fesser wrote:
>> .oO(Jerry Stuckle)
>>
>>> On 1/21/2012 2:31 PM, Chuck Anderson wrote:
>>>> J.O. Aho wrote:
>>>> >
>>>> > I have to say it feels quite much of extra work, writing the php
>>>> > script which generates the css, as you need to edit the php file,
>>>> > then
>>>> > IMHO you can quite easily edit a css instead.
>>>>
>>>> I edit one php file and then simply invoke it. There is very little
>>>> more
>>>> "work."
>>>>
>>>> [...]
>>>
>>> I agree with J.O. Seems overly complicated to have to edit a PHP file
>>> which then generates the CSS. Much easier just to edit the CSS -
>>> especially when you have syntax-sensitive editors for CSS available.
>>
>> The whole point of using PHP for creating the CSS is to avoid having to
>> edit a dozen places in the CSS to change some color for example. Instead
>> you make use of PHP and variables. Much simpler.
>>
>> And if you still want a "static" CSS for performance reasons, you have
>> to preprocess it. Calling a script for doing this is not much work.
>> Dependent on the used IDE this could even be automated in the build and
>> upload process.
>>
>> Micha
>>
>
> Create your .css properly and you don't need to do that.
>

I use my css generating file, which I would hardly call a script (fopen,
fwrite, fclose), as a template for whatever miscellaneous project I end
up working on. I write lots of browser based web apps and this makes for
a real shortcut, as all I have to do is plug in some basic colors and I
get a style sheet with all the selectors I'm used to having available in
whatever color scheme I choose. At any time during or after development
I can stop using the script and just edit the style sheet directly - but
as long as I'm fiddling with colors I leave it dynamic.

It seems an unnecessary waste of server resources to keep calling the
php preprocesssor every time a page loads the .php style sheet. And it
also seems like using a header of Content-type: text/css for a php file
is a bit of a kludge.

But, to each their own - and for their own purposes. My method works
great for my needs.

--
*****************************
Chuck Anderson • Boulder, CO
http://cycletourist.com
Turn Off, Tune Out, Drop In
*****************************
Re: Parsing .css files with php: Cons? [message #176753 is a reply to message #176751] Sun, 22 January 2012 04:14 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 1/21/2012 8:17 PM, Chuck Anderson wrote:
> Jerry Stuckle wrote:
>> On 1/21/2012 4:22 PM, Michael Fesser wrote:
>>> .oO(Jerry Stuckle)
>>>
>>>> On 1/21/2012 2:31 PM, Chuck Anderson wrote:
>>>> > J.O. Aho wrote:
>>>> >>
>>>> >> I have to say it feels quite much of extra work, writing the php
>>>> >> script which generates the css, as you need to edit the php file,
>>>> >> then
>>>> >> IMHO you can quite easily edit a css instead.
>>>> >
>>>> > I edit one php file and then simply invoke it. There is very little
>>>> > more
>>>> > "work."
>>>> >
>>>> > [...]
>>>>
>>>> I agree with J.O. Seems overly complicated to have to edit a PHP file
>>>> which then generates the CSS. Much easier just to edit the CSS -
>>>> especially when you have syntax-sensitive editors for CSS available.
>>>
>>> The whole point of using PHP for creating the CSS is to avoid having to
>>> edit a dozen places in the CSS to change some color for example. Instead
>>> you make use of PHP and variables. Much simpler.
>>>
>>> And if you still want a "static" CSS for performance reasons, you have
>>> to preprocess it. Calling a script for doing this is not much work.
>>> Dependent on the used IDE this could even be automated in the build and
>>> upload process.
>>>
>>> Micha
>>>
>>
>> Create your .css properly and you don't need to do that.
>>
>
> I use my css generating file, which I would hardly call a script (fopen,
> fwrite, fclose), as a template for whatever miscellaneous project I end
> up working on. I write lots of browser based web apps and this makes for
> a real shortcut, as all I have to do is plug in some basic colors and I
> get a style sheet with all the selectors I'm used to having available in
> whatever color scheme I choose. At any time during or after development
> I can stop using the script and just edit the style sheet directly - but
> as long as I'm fiddling with colors I leave it dynamic.
>
> It seems an unnecessary waste of server resources to keep calling the
> php preprocesssor every time a page loads the .php style sheet. And it
> also seems like using a header of Content-type: text/css for a php file
> is a bit of a kludge.
>
> But, to each their own - and for their own purposes. My method works
> great for my needs.
>

I have a template css file I just edit as required. Actually, I have
several, with different options.

When I need a new style sheet, I just pick the closest template to what
I want, modify it and try it out. I even keep a copy open in an editor
on my development system - that way when I want to try something
different, make a change and save it. The change is immediately available.

The only thing I use PHP for is to determine which template to load for
a user if I have different themes available on the website.

And a content-type header is needed for any file that's not html.
That's just normal operation (in any language).

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: Parsing .css files with php: Cons? [message #176762 is a reply to message #176749] Sun, 22 January 2012 21:35 Go to previous messageGo to next message
Michael Fesser is currently offline  Michael Fesser
Messages: 215
Registered: September 2010
Karma: 0
Senior Member
.oO(Beauregard T. Shagnasty)

> Michael Fesser wrote:
>
>> The whole point of using PHP for creating the CSS is to avoid having to
>> edit a dozen places in the CSS to change some color for example. Instead
>> you make use of PHP and variables. Much simpler.
>
> For one color, in a properly "optimized" CSS file, shouldn't there just
> be one place there as well?

Maybe it's personal preference, but I wouldn't do it. For me it would
mean to "sort" the CSS by properties instead of elements. But I don't
want to spread the properties of an element across the entire CSS: the
background color here, the foreground color there, the border style
somewhere else. Instead I keep them together.

Micha

--
http://mfesser.de/blickwinkel
Re: Parsing .css files with php: Cons? [message #176763 is a reply to message #176750] Sun, 22 January 2012 21:35 Go to previous messageGo to next message
Michael Fesser is currently offline  Michael Fesser
Messages: 215
Registered: September 2010
Karma: 0
Senior Member
.oO(Jerry Stuckle)

> On 1/21/2012 4:22 PM, Michael Fesser wrote:
>>
>> The whole point of using PHP for creating the CSS is to avoid having to
>> edit a dozen places in the CSS to change some color for example. Instead
>> you make use of PHP and variables. Much simpler.
>>
>> And if you still want a "static" CSS for performance reasons, you have
>> to preprocess it. Calling a script for doing this is not much work.
>> Dependent on the used IDE this could even be automated in the build and
>> upload process.
>
> Create your .css properly and you don't need to do that.

A typical short-sighted answer.

Another example: Assuming I want to use different color schemes on
different parts of the website, each with different nuances of the base
color. Of course I could edit the CSS by hand and calculate all needed
values by myself - a background color here, a border color there, some
text colors and others -, but I could also let PHP do the work: I just
define the base color and all others are calculated automatically.

And there are many other situations where some programming or
conditional logic in the CSS might come in handy, which has absolutely
nothing to do with your "properly created" CSS.

The only question - and what this sub-thread is all about - is whether
you want to have the CSS script parsed everytime or if you want to cache
the result. The latter is what Chuck does by calling his generator
script.

Micha

--
http://mfesser.de/blickwinkel
Re: Parsing .css files with php: Cons? [message #176767 is a reply to message #176763] Sun, 22 January 2012 23:14 Go to previous messageGo to next message
Peter H. Coffin is currently offline  Peter H. Coffin
Messages: 245
Registered: September 2010
Karma: 0
Senior Member
On Sun, 22 Jan 2012 22:35:08 +0100, Michael Fesser wrote:

> A typical short-sighted answer.
>
> Another example: Assuming I want to use different color schemes on
> different parts of the website, each with different nuances of the
> base color. Of course I could edit the CSS by hand and calculate all
> needed values by myself - a background color here, a border color
> there, some text colors and others -, but I could also let PHP do
> the work: I just define the base color and all others are calculated
> automatically.
>
> And there are many other situations where some programming or
> conditional logic in the CSS might come in handy, which has absolutely
> nothing to do with your "properly created" CSS.
>
> The only question - and what this sub-thread is all about - is whether
> you want to have the CSS script parsed everytime or if you want
> to cache the result. The latter is what Chuck does by calling his
> generator script.

No.

You supply secondary ones that override the master/main one. Master one
referred to by absolute location, site-section overrides use relative
location*, per-page overrides get embedded. That's why they're called
"Cascading".

----------------------
* You are sectioning your site by directory hierarchy, aren't you? If
not, you richly deserve whatever you get. If you're depending on a
CMS, let the CMS deal with it.

--
Frankly, your argument wouldn't float were the sea composed of mercury.
-- Biff
Re: Parsing .css files with php: Cons? [message #176769 is a reply to message #176762] Mon, 23 January 2012 00:19 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 1/22/2012 4:35 PM, Michael Fesser wrote:
> .oO(Beauregard T. Shagnasty)
>
>> Michael Fesser wrote:
>>
>>> The whole point of using PHP for creating the CSS is to avoid having to
>>> edit a dozen places in the CSS to change some color for example. Instead
>>> you make use of PHP and variables. Much simpler.
>>
>> For one color, in a properly "optimized" CSS file, shouldn't there just
>> be one place there as well?
>
> Maybe it's personal preference, but I wouldn't do it. For me it would
> mean to "sort" the CSS by properties instead of elements. But I don't
> want to spread the properties of an element across the entire CSS: the
> background color here, the foreground color there, the border style
> somewhere else. Instead I keep them together.
>
> Micha
>

Yes, it's a matter of style. But I prefer to keep all items of the same
color together. That way when I want to change the color there's only
one place to change the code when I want to change colors.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: Parsing .css files with php: Cons? [message #176770 is a reply to message #176767] Mon, 23 January 2012 00:21 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 1/22/2012 6:14 PM, Peter H. Coffin wrote:
> On Sun, 22 Jan 2012 22:35:08 +0100, Michael Fesser wrote:
>
>> A typical short-sighted answer.
>>
>> Another example: Assuming I want to use different color schemes on
>> different parts of the website, each with different nuances of the
>> base color. Of course I could edit the CSS by hand and calculate all
>> needed values by myself - a background color here, a border color
>> there, some text colors and others -, but I could also let PHP do
>> the work: I just define the base color and all others are calculated
>> automatically.
>>
>> And there are many other situations where some programming or
>> conditional logic in the CSS might come in handy, which has absolutely
>> nothing to do with your "properly created" CSS.
>>
>> The only question - and what this sub-thread is all about - is whether
>> you want to have the CSS script parsed everytime or if you want
>> to cache the result. The latter is what Chuck does by calling his
>> generator script.
>
> No.
>
> You supply secondary ones that override the master/main one. Master one
> referred to by absolute location, site-section overrides use relative
> location*, per-page overrides get embedded. That's why they're called
> "Cascading".
>

Exactly!



--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: Parsing .css files with php: Cons? [message #176779 is a reply to message #176767] Mon, 23 January 2012 22:44 Go to previous message
Michael Fesser is currently offline  Michael Fesser
Messages: 215
Registered: September 2010
Karma: 0
Senior Member
.oO(Peter H. Coffin)

> On Sun, 22 Jan 2012 22:35:08 +0100, Michael Fesser wrote:
>>
>> And there are many other situations where some programming or
>> conditional logic in the CSS might come in handy, which has absolutely
>> nothing to do with your "properly created" CSS.
>>
>> The only question - and what this sub-thread is all about - is whether
>> you want to have the CSS script parsed everytime or if you want
>> to cache the result. The latter is what Chuck does by calling his
>> generator script.
>
> No.

?

> You supply secondary ones that override the master/main one. Master one
> referred to by absolute location, site-section overrides use relative
> location*, per-page overrides get embedded. That's why they're called
> "Cascading".

What does this have to do with the issue discussed in this thread? Of
course I make use of the cascade where appropriate. But I also use PHP
to generate parts of my stylesheets when it makes sense.

Micha

--
http://mfesser.de/blickwinkel
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: phpinfo is not showing in php4 version
Next Topic: arrays with holes
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Nov 24 07:28:13 GMT 2024

Total time taken to generate the page: 0.03741 seconds