Hi--
Sweet module--thanks much for making it available.
I have a custom node.tpl.php file; in this file I want to display some videos if they exist. I have code like (pseudo code below):
if($field_video) {
print '<h4>Videos</h4>';
foreach($field_video as $item) {
print $item['view'];
}
}
The problem is that the array $field_video exists even if there are no video values in the array; as such the H4 element is printed even if there are no $items returned by the foreach loop. I'd expect that if no video items have been submitted the statement if($field_video) would evaluate to FALSE.
Other CCK fields behave this way; is there another method I should use to evaluate if $field_video contains any items? Or is this an issue I should submit to the CCK issue queue?
Thanks again,
pp
Comments
Comment #1
avpadernoVerify the array is not empty with a call to
empty(); if the array is not empty, then you can execute the loop to get its content, and print it.Comment #2
ppmax commentedThanks for the reply--much appreciated.
php.net/manual/en says:
>>empty() is the opposite of (boolean) var, except that no warning is generated when the variable is not set.
Calling !empty($field_video) vs. if($field_video) does the same thing (minus potential warnings).
Here's the thing: the array is not empty when (I assume) it should be. Here's what my $field_video array returns when no video items have been added:
The array has keys|values (element [0]=>Array()...) so no matter what I call it's still going to evaluate to TRUE when it seems like it should be FALSE when no items have been added. I can work around this by:
if($field_video[0]['view'])...
...but should the array even be built if no values have been submitted?
thx again,
pp
Comment #3
avpadernoI would expect the CCK field to act like the others; there aren't any written rules that a CCK field must follow for the value returned in such cases.
Maybe it's better to not make assumptions about the returned value.
A word from the maintainer would be appreciated.
Comment #4
funkeyrandy commentedagreed this is still confirmed behavior...need to clear that array totally if the clips have been removed....anyone?? For me..im lightboxing the clips and it thinks there are 8 when there are only 4 and the other 4 have been deleted
thanks
Comment #5
avpadernoI am closing this issue, which is for a not supported Drupal version.