3 way PHP conditional for Body ID

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
shanDB
Forum Newbie
Posts: 2
Joined: Mon Feb 07, 2011 12:05 am

3 way PHP conditional for Body ID

Post by shanDB »

Hi,

I've written a conditional statement to give my body tag a unique ID, depending on three conditions. (body id="red" etc..)

The statement does indeed work when tested, but dreamweaver is highlighting the conditional in yellow - So I'm wondering if there is an alternate (and perhaps cleaner) way of writing the following..

It's for a joomla site btw..

(I've spread the code out a little here, so it's easier for you guys to see what I'm doing)

Code: Select all

<body 

<?php if($this->countModules('headerlow')) : ?>   
	id="up"
<?php endif; ?>

<?php if (JRequest::getVar('Itemid')==104) { ?>
	id="red"

<? } else {?> 
	id="low" 
<? } ?>

>
shanDB
Forum Newbie
Posts: 2
Joined: Mon Feb 07, 2011 12:05 am

Re: 3 way PHP conditional for Body ID

Post by shanDB »

all good, I've ended up with this much more elegant solution:

Code: Select all

<?php if($this->countModules('headerlow')) {
$bodyid = 'id="up"';
} else if (JRequest::getVar('Itemid')==104) {
$bodyid = 'id="red"';
} else {
$bodyid = 'id="low"';
} ?>
<body <?php echo $bodyid; ?>>
Post Reply