【问题标题】:Drupal 7 - node custom displayDrupal 7 - 节点自定义显示
【发布时间】:2012-06-02 10:13:09
【问题描述】:

我遇到了这个问题。我创建了文件 node--mycontenttype.tpl.php 以自定义方式显示节点。我已经通过 print_r($content) 列出了所有的 $content 数组。我可以显示除 CCK 字段之外的所有变量。例如我可以打印出像这样的节点类型:

<?php print $content['body']['#bundle']; ?>

但如果我尝试显示任何 CCK 字段,例如:

<?php print $content['body']['#object']->field_url[und][0]['value']; ?>

它给了我一个错误“注意:使用未定义的常量 und - 假定 'und' w include()”。好吧,所以“und”表示语言的“未定义”,但“pl”和“en”都不能解决问题。我该如何管理?

【问题讨论】:

    标签: drupal-7 cck nodes


    【解决方案1】:

    好的,经过研究,我终于找到了答案。它有效,但在某些情况下它看起来有点低效。代码如下:

    <?php 
    $output = field_get_items('node', $node, 'field_url');
    $output = $output[0]['safe_value'];
    print $output;
    ?>
    

    但是如果你有很多 CCK 字段,看起来你必须多次启动 field_get_items() 函数。如果你们中的任何人知道更好的方法,您可以分享一下。

    【讨论】:

      【解决方案2】:

      当您编写[und] 时,Drupal (PHP) 假定在代码中的某处定义了变量$und

      你应该使用:

      <?php print $content['body']['#object']->field_url['und'][0]['value']; ?>
      

      【讨论】:

        猜你喜欢
        • 2015-10-10
        • 2014-08-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-04-23
        相关资源
        最近更新 更多