主题 Drupal 对多个字段进行分组
我的内容类型包含 4 个图像。
在我看来,它们被分组(对多个值进行分组)。
我想将每个图像放在单独的li中,例如:
<ul class="list">
<li><img src="/images/image1.jpg"/></li>
<li><img src="/images/image2.jpg"/></li>
<li><img src="/images/image3.jpg"/></li>
<li><img src="/images/image4.jpg"/></li>
</ul>
如何实现这一点?我假设我需要使用 foreach 循环对字段模板文件进行主题化,但我不太清楚我应该做什么。
谢谢 :)
I have a content type that has 4 images to it.
In my View they are grouped (Group Multiple Values).
I want to put each image in a seperate li, such as:
<ul class="list">
<li><img src="/images/image1.jpg"/></li>
<li><img src="/images/image2.jpg"/></li>
<li><img src="/images/image3.jpg"/></li>
<li><img src="/images/image4.jpg"/></li>
</ul>
How do I achieve this? I assume I need to theme the field template file with a foreach loop, but I can't quite figure out what I'm supposed to be doing.
Thanks :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Ran 发布的链接似乎是关于如何查找视图模板的一个很好的演练。为视图设置主题与为其他任何内容设置主题没有太大区别,唯一棘手的部分是确定要覆盖哪个模板以及调用它的内容。此信息可以在视图 UI 中的主题信息下找到。
无论如何,一旦您开始(请记住清除缓存以使 Drupal 使用您的新模板),可能很难弄清楚您可以使用哪些变量等来按照您想要的方式自定义视图。随着时间的推移,这会变得更容易,但我通常使用的策略是 devel 模块与 dpm() 一起使用。这可以为您漂亮地打印变量,并且可以更轻松地查看您需要更改什么/如何更改才能获得您想要的标记。还要记住在视图模板中准备好注释,它有关于它为您提供哪些变量的良好文档。
The link Ran posted seems like a fine walkthrough of how to find view templates. Theming a view is not much different than theming anything else, the only tricky part is figuring out which template to override and what to call it. This information can be found in the views UI, under Theme information.
Anyways, once you get started (remember to clear cache to make Drupal use your new template), it can be hard to figure out what variables etc. you have available in order to customize the view the way you want. This gets easier over time, but a strategy I usually use, is the devel module along with
dpm()
. This pretty prints variables for you, and makes it a lot easier to see what/how you need to change in order to get the markup you want. Also remember to ready the comments in the views templates, it has good documentation about which variables it makes available for you.使用视图主题来做到这一点。这将是一件非常容易的事情,但需要您进行一些编码(不是太多)。
这是一个很好的入门指南:http://www.appnovation.com /theming-views-drupal-6-simple-way
use views theming to do that. It will be very easy thing to do but it will require you a little bit coding (not so much).
This is a great guide to start: http://www.appnovation.com/theming-views-drupal-6-simple-way
伙计们,感谢你们的帮助,你们把我推向了正确的方向。
我通过覆盖 template.php 中名为 theme_content_view_multiple_field 的函数来解决这个问题。
最终我将对其进行编辑,使其仅影响此特定字段(例如 http://drupal.org/node/556232)
干杯:)
Guys thanks for all your help, you pushed me in the right direction.
I got round this by overriding a function called theme_content_view_multiple_field in my template.php
Eventually I will edit it so that it only affects this particular field (such as http://drupal.org/node/556232)
Cheers :)
谢谢汤姆!这对于 Drupal 6 来说就像一个魅力。这里有一些额外的行,保留默认标记 (DIV) 并将特定字段更改为 LI,其中 FIELDNAME 是 CCK 字段的计算机名称。
Thanks Tom! That worked like a charm for Drupal 6. Here are a few extra lines that keep the default tag (DIV) and change to LI for a specific field, where FIELDNAME is the machine name of your CCK field.