【问题标题】:Drupal 6 CCK Field Not ShowingDrupal 6 CCK 字段未显示
【发布时间】:2011-07-22 19:07:28
【问题描述】:

在 Drupal 6 中,我向自定义内容类型添加了自定义字段。

名称是:“field_publishedin”

然后我在该字段中添加了一些示例文章的数据。

在它的视图中,我也添加了该字段。

在呈现它的页面上,我还添加了代码以显示该字段:

<div class="press-content">
<div class="family-news">
<?php foreach($rows as $row): ?>
<div class="news">
    <div class="data">Posted on <a href="<?php print url('news/'.$row['created_1']) ?>">           <?php print $row['created'] ?></a> </div><!--DATA-->
    <h4><?php print $row['title'] ?><span><?php print $row['field_publishedin_value']; ?></span></h4>
</div><!--NEWS-->
<?php endforeach ?>
</div>
</div>

所以我添加的代码是&lt;span&gt;&lt;?php print $row['field_publishedin_value']; ?&gt;&lt;/span&gt;,因为根据在模板中使用时的视图,您应该添加“_value”。

但是,我点击了重新扫描模板,清空了 drupal 缓存,但新代码仍然没有呈现在页面上。

当我将此添加到页面时:&lt;?php print '&lt;pre&gt;' . htmlentities(print_r($rows, 1)) . '&lt;/pre&gt;'; ?&gt; 并输出它未显示的可能数组值“field_publishedin_value”,因此模板似乎不知道该字段存在,即使它在视图中。帮忙?

【问题讨论】:

    标签: drupal


    【解决方案1】:

    安装devel模块,并在*.tpl.php中,放置:

    <?php
    dpm($fields); // if views 
    // or dpm($node); if it's a node or page.tpl.php
    // of if you don't know, dpm(get_defined_vars());
    ?>
    

    另外,如果这是视图,您应该使用的模板是 views-view-fields.tpl.php。注意 PLURAL 字段。

    【讨论】:

    • 它在以下模板中:views-view-table--news.tpl.php 另一个编码器让它工作,但即使查看所有代码和后端也无法弄清楚他们是如何做到的。但还没有收到他们关于他们是如何做到这一点的回音,因此同时试图自己弄清楚。
    • 哦,添加该代码仅输出与我在上面的问题中的代码相同的内容: ' 。 htmlentities(print_r($rows, 1)) 。 ''; ?> 如前所述,它没有在可用数组中显示 field_published_in,这意味着问题出在某处招聘但无法弄清楚是什么。
    • 如果 var 不在 $fields 数组中,则视图不会将其发送到模板。您没有在该字段的视图 ui 中选中“从显示中排除”是吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-25
    • 1970-01-01
    相关资源
    最近更新 更多