Drupal 6 中的主题化节点主体
我试图让 Drupal 输出具有特定类名的 div 标签中特定内容类型的正文。
首先,我尝试覆盖 node.tpl.php,但我发现此处的 $content 变量已经包含正文以及其他自定义 cck 字段。而我想做的正是将身体与其他领域分开。
之后我查看了 content-field.tpl.php 并发现它仅针对自定义 cck 字段执行。所以也不适合我。
那么..如何主题化节点主体字段?
I'm trying to make Drupal output the body of a particular content type in div tag with certain class name.
First, I tried to override node.tpl.php, but I discovered $content variable here already contains body along with additional custom cck fields. And what I'm trying to do is precisely to separate body from another fields.
After that I looked at content-field.tpl.php and found it's executed only for custom cck fields. So doesn't suit me too.
So.. how to theme a node body field?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
首先调用
This is what you node object contains - 你可以直接使用它的任何成员,而不仅仅是打印内容。分析这个,你就会知道到底要调用什么;)
在正文的情况下,可以通过以下方式访问无样式内容:
对于其他字段,你可以:(
其中 [0] 是数组中项目的索引 - 有用当您可以上传许多图片时使用 ImageField)。
例如,这是我的
node-event.tpl.php
的内容,显示有关事件的详细信息:Start by calling
This is what you node object contains - and you can use any of its members directly instead of just printing the content. Analyse this and you'll know what to call exactly ;)
In case of the body, the unstyled content can be accessed with:
For other fields, you do:
(where [0] is the index of the item in the array - useful for ImageField when you can upload many pictures).
For example, here's the content of my
node-event.tpl.php
, displaying details about an event:看看这个:http://capellic.com/blog/theming-the -节点主体字段
Take a look at this: http://capellic.com/blog/theming-the-node-body-field
如果您需要非常灵活,对我来说最好的方法是转到此页面:
admin/content/node-type/[ContentType]/display/basic
并将所有附加字段设置为“隐藏”。
然后,
$content
变量将仅包含 body 字段。缺点是需要一一显示所有附加字段。 CCK 提供了一种简单的方法,通过为每个字段提供完全呈现的变量
,您可以真正轻松地自定义内容类型的输出。
If you need to be very flexible, the best way for me is to go to this page :
admin/content/node-type/[ContentType]/display/basic
And set all your additional fields to "hidden".
Then, the
$content
variable will contain only the body field.The drawback is that you need to display all the additional fields one by one. CCK provide an easy way to do that by providing a fully rendered variable for each field
Using that, you can really customize easily the output for a content type.