Drupal:在节点模板中循环field_image的最干净的方法


Drupal : Cleanest way to loop throught field_image in a node template

我正在为我的新Drupal 7主题中的一个节点创建主题,我想使用带有自定义标记的幻灯片。

我的节点有一个包含多个图像的图像字段(field_image)。

现在我可以检索生成代码与此:

$node = node_load($nid);
$image = $content['field_image']["#object"]->field_image;
//htmldump($image);
foreach ($image as $key=>$value) {
  $output = field_view_value('node', $node, 'field_image', $image[$key], array(
    'type' => 'image',
    'settings' => array(
      'image_style' => 'thumbnail', //place your image style here
      'image_link' => 'content',
    ),
  ));
  print render($output);
}

这还可以,但我不确定这是最好的方法。

1) 我如何使用"建议"或"钩子"(我不太熟悉这个概念,只是在我的template.php中默认使用了这些)

2) $content['field_image']["#object"]->field_image;是否具有健壮性和可更新性?

编辑:<div class="b-slick"> <div class="b-slick__slide"><img typeof="foaf:Image" src="http://localhost/blabla/pic1.jpg" width="978" height="651" alt=""></div> <div class="b-slick__slide"><img typeof="foaf:Image" src="http://localhost/blabla/pic2.jpg" width="978" height="651" alt=""></div> </div>

您可以使用以下代码:

<?php 
foreach ($content['field_images'] as $key=>$image):
if(is_numeric($key)): 
print render($content['field_images'][$key]); 
endif;
endforeach;
?>