【问题标题】:Unable to print CCK field in template in Drupal无法在 Drupal 的模板中打印 CCK 字段
【发布时间】:2010-09-28 20:19:05
【问题描述】:

我正在尝试像这样在我的 node.tpl.php 文件中打印 CCK 字段; print $node->field_name_here[0]['view']; 但是当我导航到该页面时,我看不到内容。 即使我使用print_r($node);,我也看不到有关该变量的任何信息。 Drupal 只渲染 node.tpl.php 文件中的所有其他内容。

但是...如果我通过将 die(); 放在 print_r() print $node->field_name_here[0]['view']; 之后的任何位置来停止 node.tpl.php 的执行,CCK 字段/变量将按应有的方式呈现。

这不是权限问题,因为我已允许所有用户查看这些字段的内容。我什至尝试禁用和卸载 CCK 字段权限-模块,但仍然无法在我的模板中正确打印 CCK 字段。

我在这里错过了什么?

【问题讨论】:

  • 您是否检查了页面源以获得预期的输出? die(); 语句通常对已打印的内容没有影响,所以我怀疑您的输出在页面上,但由于 CSS/标记,在浏览器中不可见。

标签: php drupal cck


【解决方案1】:
$node = (object) $node;
$node = node_build_content($node, $teaser, $page);
$content = drupal_render($node->content);
// 允许模块修改完全构建的节点。
node_invoke_nodeapi($node, 'alter', $teaser, $page);
返回$节点;

只需使用上面的代码行传递您加载的节点。这将返回节点的[视图]。

【讨论】:

    【解决方案2】:

    检查内容类型显示选项卡。 example.com/admin/content/node-type/{content-type}/display

    很有可能您尝试使用的字段的显示设置为无,“排除”复选框被选中。

    【讨论】:

      【解决方案3】:

      应该是下面这个吧?

       print $node->field_name_here[0]['value']; 
      

      相反? (值而不是视图)-在脚本中我像这样访问它们,它也显示在节点的开发选项卡上

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-12-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多