dozabg1616 2013-11-22 21:28
浏览 47
已采纳

如何在Drupal 7中显示数组的所有值

I'm working on a Drupal 7 site with an event listing. I've added a date field so the user can specify the date or dates for the event. Now I'm trying to get the date(s) to show in the template. I've tried using this:

<?php print $node->field_event_date['und'][0]['value']; ?>

That works ok, but it only shows one event from the array. I could just repeat that line 10 times and replace the array item number in each one, but I figure there has to be a way to show all the items in an array, whether it's one or ten. Can this be done with PHP or do I need to make a View?

  • 写回答

1条回答 默认 最新

  • donglu953744 2013-11-22 22:13
    关注

    In PHP terms you're probably looking for a foreach loop, to iterate over the array and print the values.

    In Drupal terms, you'll want to use that with the field_get_items() function:

    $items = field_get_items('node', $node, 'field_event_date');
    foreach ($items as $item) {
      print $item['value'];
    }
    

    For bonus fun, check out EntityMetadataWrappers

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划