开发者

comma separated views 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!


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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜