Jump to content

3 way PHP conditional for Body ID


shanDB

Recommended Posts

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)

 

<body 

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

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

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

>

Link to comment
Share on other sites

Your way is messy, but fine. It's just developer preference. Another way of doing it would be..

 

<?php

if($this->countModules('headerlow')) // or isset($this->countModules('headerlow'))), i don't understand the orig line.
{
    $id = 'up';
}

if(JRequest::getVar('Itemid') == 104)
{
    $id = 'red';
}
else
{
    $id = 'low';
}
?>
<body id="<?php echo $id; ?>">

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.