Drupal render()强制其他div关闭?

时间:2011-09-22 15:32:19

标签: drupal-7 drupal-theming

我是Drupal主题的新手,我正在尝试为我所拥有的特定内容类型创建自定义主题模板。

我正在尝试以下方法:

<div<?php print $content_attributes; ?>>


    <?php print render($content['field_property_media']); ?>

    <div class="field-label-above property-information">
        <div class="field-label">Property Information</div>
        <?php print render($content['address']); ?>

    </div>

</div>

但是,当内容实际呈现时,地址部分将从其父div启动,如下所示:

<div class="field-label-above property-information">
    <div class="field-label">Property Information</div>

</div>
<div class="field field-name-field-property-address field-type-addressfield field-label-inline clearfix"><div class="field-label">Address:&nbsp;</div><div class="field-items"><div class="field-item even"><div class="street-block"><div class="thoroughfare">55 Duchess Ave</div></div><div class="addressfield-container-inline locality-block"><span class="locality">London</span>&nbsp;&nbsp;<span class="state">Ontario</span>&nbsp;&nbsp;<span class="postal-code">N6C 1N3</span></div><span class="country">Canada</span></div></div></div>

我无法弄清楚为什么会发生这种情况,或者解决方法是将地址保留在我手动创建的div中。

思想?

1 个答案:

答案 0 :(得分:1)

唯一可能发生这种情况的方法是,如果你有一个自定义或贡献的模块拦截你的模板文件并进行更改,或者如果你启用了一些javascript,那么它会将<div>移出它的容器。 Drupal在处理模板文件时绝对不对内容进行重新排序,因此它不会是Drupal核心中导致问题的任何内容。

如果<div>只是在容器外面显示(即当你检查源代码时它在里面),那么你可能只是面临浮动问题;只需将clearfix类添加到包含元素。

修改

只是想一想,自从您添加了模板文件后,您是否清除了缓存?如果没有,那么这样做,在清除缓存之前不会被接收。

此外,如果这是一个自定义节点模板(即node - page.tpl.php),请确保您还将node.tpl.php复制到主题文件夹中。然后再次清除缓存。