逗号分隔的视图列表

发布于 2024-11-07 06:16:48 字数 330 浏览 0 评论 0原文

每个人。我的视图 2 有问题。我有一个视图,行的样式设置为字段(只有标题字段)。我想用逗号分隔列表显示这些标题。 例如:

哈萨克斯坦、英国、中国、韩国

试图这样做:

foreach($fields['title']->content as $titles) {

$zagolovki[] = $titles['view'];

}

$title_list = implode(', ', $zagolovki);

print $title_list;

但它不起作用 - 说论证错误。请帮助我在视图中用逗号分隔列表显示节点标题。谢谢!

everyone. I've got a problem with Views 2. I have a view with row's style set to fields (Got only title field). I want to display these titles with comma separated list.
For example:

Kazakhstan, England, China, Korea

tried to do this:

foreach($fields['title']->content as $titles) {

$zagolovki[] = $titles['view'];

}

$title_list = implode(', ', $zagolovki);

print $title_list;

but it doesn't works - says error in argument. Please help me someone to display node titles in views with comma separated list. Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

魔法唧唧 2024-11-14 06:16:48

我快速查看了视图模块附带的 views-view-fields.tpl.php ,它显示“

 /*
 * - $view: The view in use.
 * - $fields: an array of $field objects. Each one contains:
 *   - $field->content: The output of the field.
 *   - $field->raw: The raw data for the field, if it exists. This is NOT output safe.
 *   - $field->class: The safe class id to use.
 *   - $field->handler: The Views field handler object controlling this field. Do not use
 *     var_export to dump this object, as it can't handle the recursion.
 *   - $field->inline: Whether or not the field should be inline.
 *   - $field->inline_html: either div or span based on the above flag.
 *   - $field->separator: an optional separator that may appear before a field.
 * - $row: The raw result object from the query, with all data it fetched.
 */

所以我认为 $fields 是您应该迭代的内容”。如果您想调试 $fields 的结构,请安装 devel-module并使用 dpm() 或 <一个href="http://drupalcontrib.org/api/drupal/contributions--devel--devel.module/function/dsm/6" rel="nofollow">dsm() 显示<的内容代码>$字段。也许采用您编辑的模板(这应该是 views 中的 view-module 模板之一/theme 文件夹)并看看那里发生了什么。

I quikly took a look in the views-view-fields.tpl.php that comes with the views module and it says

 /*
 * - $view: The view in use.
 * - $fields: an array of $field objects. Each one contains:
 *   - $field->content: The output of the field.
 *   - $field->raw: The raw data for the field, if it exists. This is NOT output safe.
 *   - $field->class: The safe class id to use.
 *   - $field->handler: The Views field handler object controlling this field. Do not use
 *     var_export to dump this object, as it can't handle the recursion.
 *   - $field->inline: Whether or not the field should be inline.
 *   - $field->inline_html: either div or span based on the above flag.
 *   - $field->separator: an optional separator that may appear before a field.
 * - $row: The raw result object from the query, with all data it fetched.
 */

So I think $fields is what you should iterate over. If you want to debug the structure of your $fields install the devel-module and use dpm() or dsm() to display the content of $field. Maybe take the template you edited (that should be one of the view-module templates in the views/theme folder) and look what happens there.

和影子一齐双人舞 2024-11-14 06:16:48

但它说错误发生在哪里? nonsenz 可能是对的,$fields['title']->content 不是数组。仅用于调试,请尝试

print("array content: "+ is_array($fields['title']->content));

在 foreach 之前添加。如果您知道 $fields 是一个小的嵌套结构,您可以尝试

print(str_replace("\n","<br/>",print_r($fields,true));

查看其中到底包含什么,以便您可以验证您尝试迭代的内容实际上是可迭代的。

Where does it say the error occurs, though? nonsenz is probably right that $fields['title']->content is not an array. For debugging only, try adding

print("array content: "+ is_array($fields['title']->content));

before the foreach. If you know that $fields is a small nested structure, you can try a

print(str_replace("\n","<br/>",print_r($fields,true));

to see what exactly is in it, so that you can make verify that what you're trying to iterate over is in fact iterable.

小…红帽 2024-11-14 06:16:48

我创建了这个模块:

http://drupal.org/project/views_delimited_list

我也不是确保摆弄选项来仅创建逗号分隔的列表。你应该可以,如果你不能,我会解决它。

I've created this module:

http://drupal.org/project/views_delimited_list

I'm not too sure about fiddling with the options to create merely a comma-separated list. You should be able to, and if you can't I'll fix it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文