逗号分隔的视图列表

时间:2011-05-14 18:19:45

标签: drupal views

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

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

尝试这样做:

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

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

}

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

print $title_list;

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

3 个答案:

答案 0 :(得分:1)

我快速查看了视图模块附带的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()dsm()来显示$field的内容。也许拿你编辑的模板(应该是views/theme文件夹中的view-module模板之一)看看那里发生的事情。

答案 1 :(得分:0)

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

print("array content: "+ is_array($fields['title']->content));
在foreach之前。如果您知道$ fields是一个小的嵌套结构,您可以尝试

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

查看其中的确切内容,以便您可以验证您尝试迭代的内容实际上是可迭代的。

答案 2 :(得分:0)

我创建了这个模块:

http://drupal.org/project/views_delimited_list

我不太确定如何摆弄只创建逗号分隔列表的选项。你应该能够,如果你不能,我会解决它。

相关问题