tags:

views:

75

answers:

2

I have this piece of code in my cms:

<ul class="subsection_tabs" id="tab_group_one" style="clear:none;">
    <?php if ($this->getChildHtml('description')==NULL) { echo '<div id="trollweb_1"></div>'; } else echo('
    <li class="tab"><a href="javascript:void(0);" id="trollweb_1" onClick="trollweb_tabs(1)" class="active"><h4>' . $this->__('Product Description'). '</h4></a></li> '); ?>

The problem is it always outputs the 'else'. Even though I haven't filled in the description in the back end and it is blank.

How can I fix this?

+1  A: 

If you try to not test only for NULL, but also for empty strings, then you should do

$childHtml = $this->getChildHtml('description');
if (empty($childHtml))

instead.

EDIT: As VolkerK said, empty('0') returns false as well, so that solution depends on your requirements. As it looks, like you are looking for string solutions, this is viable option, as long as you do not have '0' as values.

Residuum
Keep in mind that empty('0')===true, see http://docs.php.net/types.comparisons
VolkerK
empty only works for variables, not for return values of method calls:http://php.net/empty
middus
@middus: Good point, I have updated my answer accordingly.
Residuum
I tried your code but the li is still getting returned.
a1anm
A: 

Maybe getChildHtml() always returns a string (not NULL). And maybe the string in your test environment only contains whitespaces.
In that case trim() removes them and you can simply check the length of the string

if ( 0<strlen(trim($this->getChildHtml('description'))) ) { 
VolkerK