Drupal render() 强制其他 div 关闭?
我是 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: </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> <span class="state">Ontario</span> <span class="postal-code">N6C 1N3</span></div><span class="country">Canada</span></div></div></div>
我无法弄清楚为什么会发生这种情况,也无法弄清楚将地址保留在 div 中的解决方案是什么我手动创建的。
想法?
I'm new to Drupal theming and am attempting to create a custom theme template for a specific content type I have.
I am attempting the following:
<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>
However, when the content actually render the address portion gets booted out of its parent div and looks like this:
<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: </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> <span class="state">Ontario</span> <span class="postal-code">N6C 1N3</span></div><span class="country">Canada</span></div></div></div>
I can't figure out why this is happening or what the solution is to keep the address within the div I manually created.
Thoughts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
发生这种情况的唯一可能的方法是,如果您有一个自定义或贡献的模块拦截您的模板文件并更改它,或者您启用了一些 JavaScript,将
移出了它的文件容器。 Drupal 在处理模板文件时绝对不会对内容进行重新排序,因此 Drupal 核心中的任何内容都不会导致问题。
如果
仅显示在容器外部(即,当您检查源代码时它在容器内部),那么您可能只是面临浮动问题;只需将
clearfix
类添加到包含元素即可。编辑
只是想一下,自从添加模板文件后,您是否清除了缓存?如果没有,请执行此操作,直到清除缓存后才会拾取它。
另外,如果这是自定义节点模板(即node--page.tpl.php),请确保您也已将node.tpl.php复制到主题的文件夹中。然后再次清除缓存。
The only possible way this could happen is if you've got a custom or contributed module intercepting your template file and changing it, or if you have some javascript enabled that's moving the
<div>
out of it's container. Drupal does absolutely no re-ordering of content when it processes a template file so it can't be anything in Drupal core that's causing the problem.If the
<div>
is just displaying outside the container (i.e. it's inside when you inspect the source code) then you're probably just facing a floating issue; just add theclearfix
class to the containing element.EDIT
Just a thought, have you cleared your cache since you added the template file? If not, do that, it won't be picked up until the caches are cleared.
Also if this is a custom node template (i.e. node--page.tpl.php), make sure you've also copied node.tpl.php to your theme's folder. Then clear your cache again.