开发者

Drupal 6: pre-defined variable for amount [count] of custom type items

开发者 https://www.devze.com 2023-01-02 08:25 出处:网络
I\'m a drupal newbie... I researched but couldnot find :/ is there any predefined variable that gives my CCK field value count?

I'm a drupal newbie...

I researched but couldnot find :/ is there any predefined variable that gives my CCK field value count?

for example; I have field_logo_sponsor and I need to display all logo items. Now I have 5 item

<?php print $node->field_logo_sponsor[0]['view'] ?>
<?php print $node->field_logo_sponsor[1]['view'] ?>
<?php print $node->field_logo_sponsor[2]['view'] ?>
<?php print开发者_开发技巧 $node->field_logo_sponsor[3]['view'] ?>
<?php print $node->field_logo_sponsor[4]['view'] ?>

it is stupid to use it that way :/ if there is any count variable for that, I will just create a loop for that and display them in a for or while loop

Appreciate helps! thanks a lot!


How about:

<?php
foreach($node->field_logo_sponsor as $logo_sponsor) {
  print $logo_sponsor['view'];
}
?>

Also count($node->field_logo_sponsor) should return you the number of items.


Sidenote: never use

foreach($node->field_logo_sponsor as $logo_sponsor) {
  print $logo_sponsor['value'];
}

Even if that calue contains what you want, and the view does not contain the HTML you want. value is unescaped, meaning, it can (and therefore will, at some point) contain stuff like XSS.

0

精彩评论

暂无评论...
验证码 换一张
取 消