【发布时间】:2012-03-24 20:40:21
【问题描述】:
经过漫长的探索,终于在node.tpl.php中找到了Drupal 7中$content拆分的解决方案。
以前我用过我用过:
print $node->field_name['und'][0]['value'];
这是在发出警告:
Notice: Undefined offset: 0 in include() (line 24 of C:\xampp\htdocs\drup\sites\all\themes\myCustomTheme\node.tpl.php)
现在我正在使用下面的函数,它可以正常工作,没有错误
$output= field_get_items('node', $node, 'field_name');
$output = $output[0]['safe_value'];
print $output;
现在的问题是我的页面上有超过 50 个字段,我认为调用 field_get_items('node', $node, 'field_name') 函数 50 次效率不高。
什么是替代品? 或者我应该对 field_get_items 函数严格吗 或者我应该严格打印 $node->field_name['und'][0]['value'];我听说在 Drupal 7 中使用它不好,因为 und 是未定义的。这虽然解决了我的问题,但给出了令人讨厌的警告。
【问题讨论】: