shanDB Posted February 7, 2011 Share Posted February 7, 2011 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 https://forums.phpfreaks.com/topic/226932-3-way-php-conditional-for-body-id/ Share on other sites More sharing options...
lastkarrde Posted February 7, 2011 Share Posted February 7, 2011 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 https://forums.phpfreaks.com/topic/226932-3-way-php-conditional-for-body-id/#findComment-1170902 Share on other sites More sharing options...
shanDB Posted February 7, 2011 Author Share Posted February 7, 2011 terrific.. your code indeed did work, and using variables is a much more elegant way. Learning something new each day thanks Link to comment https://forums.phpfreaks.com/topic/226932-3-way-php-conditional-for-body-id/#findComment-1170938 Share on other sites More sharing options...
sasa Posted February 7, 2011 Share Posted February 7, 2011 after use this code the value of variables $id is newer 'up' Link to comment https://forums.phpfreaks.com/topic/226932-3-way-php-conditional-for-body-id/#findComment-1171089 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.