If else statement in a PHP stylesheet document

Hey all,

I am including a css.php stylesheet and was hoping to use some if/else statements in combination with variables that are set in the theme’s default.php file.

However, everytime i insert a variable using sessions or globals, they are not transfered.

Do you have some tips on how to create a “dynamic” php stylesheet that can access variables like if a user is logged in and also a foreach($blocks as $b) loop.

That way i can load certain css class changes depending if the user is logged in. And create a class for certain blocks.


In your header you could do something like

$u = new User();

<body class="<?php if($u->isLoggedIn()) echo "loggedIn" ?>">

them in your css you can use the loggedIn class to style the differences when users are logged in

Thanks for the tip!

But i already had a similar approach using an if statement and loading an extra css stylesheet.

However with a php stylesheet i thought i would be able to use if/else statements as wel as for loops using global variables used in Concrete CMS.

Right now i am thinking of using internal tags in the themes default.php especially for the blocks.

I still prefer a stylesheet. So hope anyone has an idea on how to fix that.

And if it is possible to access/get data from blocks in the themes default.php file.

Easiest way is to put everything in style tag (in head), like:

<?php if ($something=='something'): ?>
.some-class { color: red; ?>
<?php else: ?>
.some-class { color: blue; ?>
<?php endif; ?>

You can also move that code to separate file/files:

<?php $this->inc('elements/inline_styles.php'); ?>

If you want more complicated solution,
then yes, it is possible.
You can create php controller,
do all logic there,
“mimic” css file by changing sent header: header("Content-type: text/css");
and treat/use it as CSS stylesheet.

But this could be a little overkill for simple problems. And your development editor will still treat is as .php file, so editing that “css” won’t necessary be convenient.

Hey Parasek,

Thanks! Then i’ll just use the style tags instead.