I'm pretty sure this is a simple question, which hopefully will have a simple answer.
I've created a block in Views 2 that lists all the directors a client of mine has worked for, which I can get to display fine, but I want to have these show up in a comma separated paragraph rather than rows. The only way I've found to get something like this to happen is to set the style to "Ordered List" and then in the CSS give the li tag for that block a value of "inline". Then, to get the commas in I've had to do the following cheat in my views-view-list--resume.tpl.php file:
foreach ($rows as $id => $row):
print $row; echo ",";
endforeach; but I still get awkward spacing between the comma & the values, as well as a trailing comma after the last row is printed. I tried to play around with implodes, but I couldn't get that to work, and it seems like there is something in views already set up to have the values print out inline, but it appears to only work between two separate content fields, not the same.
Basically I want to take:
Director1
Director2
Director 3
etc....
and change it to:
Director1, Director2, Director3
Any and all help would be greatly appreciated.
Comments
_
Set the style to 'unformatted', row style to 'fields', then click on the little gear next to "fields" and select the inline fields and set the separator.
===
"Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime." - Lao Tzu
"God helps those who help themselves." - Ben Franklin
"Search is your best friend." - Worldfallz
Unfortunately that doesn't
Unfortunately that doesn't work. I tried that first, which is what let me to my goofy solution. Setting the style to "unformatted" returns the values with line breaks between them, and the inline fields section doesn't seem to do anything whatsoever.
Is there another setting hidden somewhere that might conflict with this?
_
There must be something going on because it works fine when i use it (i just tried again to be sure). I'm using views 6.3.
===
"Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime." - Lao Tzu
"God helps those who help themselves." - Ben Franklin
"Search is your best friend." - Worldfallz
hmmmm =/ I'm using views
hmmmm =/ I'm using views 2.3, but you're right there must be something else going on. When you tried it were you only printing one CCK field (containing multiple table rows)?
{grumble}
_
If you describe exactly what you want in the view, i'll try it out and see what happens.
===
"Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime." - Lao Tzu
"God helps those who help themselves." - Ben Franklin
"Search is your best friend." - Worldfallz
The inline feature is part
The inline feature is part of an unformatted row, that is it only applies to the row.
What you probably want to do is override the template for style output (it gathers the rows together). The default template is
I would make a template override something like
[Edited to change count++ to $count++]
That did the trick!
Thanks nevets! That did the trick. I had a feeling that a counter had something to do with it, but couldn't quite get it to play nice. Just in case anyone out there is trying to do this too, there is one minor change that needs to happen if you want to copy and paste nevets' code, you need to make "count++" "$count++".
Otherwise, it worked like a charm. Thanks for all of your help!
Beware of whitespace
This snippet is working, but just make sure you don't have any whitespace between the 'foreach' and 'if ( $count )', as the whitespace would appear between the items and the comma, creating a visual bug.
In Drupal 6, you can add this to a template called 'views-view-unformatted--field-myfield.tpl.php'. To get the exact name, check within Views, under 'theme information', and then 'Style Output'.
This looks like exactly the
This looks like exactly the type of answer I'm looking for, but I'm not exactly sure how to implement it.
I'm using View 6.x-2.8. I've created a content type (lodging) with a text field called 'features' which has multiple values enabled and populated. I call this field in views and trim it to 200 characters on a word boundary adding ellipses when there is more content. When I view it, it displays like this:
Features:
Hot tub
Pool
Hot Breakfast
...
and I would like it to display like this:
Features: Hot Tub, Pool, Hot Breakfast...
I'm using Style: Grid, Row Style: Fields.
I've attempted to play with a custom template views-view-fields.tpl.php, and views-view-field--field-lodging-features-value.tpl.php, but any edits I've made have been a shot in the dark, as I really am not comfortable with PHP quite yet.
The original code from Views' views-view-fields.tpl.php is:
What edits would I make to this to achieve the inline, comma-separated results I'm looking for above in a views-view-fields--field-lodging-features-value.tpl.php file?
Thanks so much for any help!
Seems like you're right on
Seems like you're right on the verge. You should be able to do this right from within views without having to create a template override.
Just change your style to "unformatted" and then click on the settings button next to "fields" and choose "features" (or whatever you want to be displayed as an inline field) as your inline field, then just enter a comma in the separator box.
You could also do it with PHP, but this is a lot more versatile and saves you having to hard code anything.
Hope that helps.
thanks it worked just fine!
thanks it worked just fine!
nope
pretty sure that isn't answering the question above. that will display a set of fields as selected inline... what is being asked (and i'd love to know) is how to get the values for a single field to list in a csv string rather than 1 per line.
ideally there would be a new formatter that would do this.
Peter Lindstrom
LiquidCMS - Content Solution Experts
customfield
my solution so far was to use Views Customfield module
and use something like this:
Peter Lindstrom
LiquidCMS - Content Solution Experts
This helps a lot actually!
This helps a lot actually! Thank-you, this snippet came in handy when working with views_data_export.
Views Delimited List
Just in case someone else find this topic
http://drupal.org/project/views_delimited_list
That's what you are looking for.
FWIW, I have tried this
FWIW, I have tried this module and it seems to work as advertised.