Closed (fixed)
Project:
Views (for Drupal 7)
Version:
6.x-2.2
Component:
Miscellaneous
Priority:
Minor
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
14 Jan 2009 at 12:35 UTC
Updated:
2 Feb 2009 at 13:20 UTC
I took a look around Views but just couldn't figure this one out and I'm not sure if it is possible right now. I want to create an index view like seen on a Wikipedia category listing or on Taxonomy VTN seen here: http://drupal.org/node/248014
This is unlike the glossary view in that the titles are not filtered by their first letter but grouped by it. As far as I could tell, you can only group by a whole title.
Comments
Comment #1
merlinofchaos commentedYou actually can do this. Add your title field to the view twice. Set one of them to 'exclude' and make it the grouping field. Then add a theme template for that field and use PHP code (specifically the substr function) to reduce the title to just one character. See the Theme: Information link in the View plus the associated help for information on theming an individual field.
Comment #3
sprior commentedmerlinofchaos, I'm trying to follow your instructions above to create a glossary type page which indexes a Node content type and groups based on first character of the Node title.
I've created a duplicate field for the Title with id title_1 and created a theme file named views-view-field--TOC--title-1.tpl.php (didn't know which of the several name options I should have used). The template file started out with a php block of "print $output;" which shows the content in the original groups, and I found that if I substituted 'print "hello";' in the php block I did see the content cluster into one group.
However I'm not yet familiar enough with Drupal's object model to know what I need to do to reduce the title to just one character. I tried '$title = substr($title, 0, 1);', but that shows 'TitleGrp:' as the group title instead of the first char of the actual title - TitleGrp is the label I gave to the duplicate title field. Can you help me fill in the correct variable to feed into the substr to get the correct result?
Comment #4
merlinofchaos commentedYou're on the right track with the substr, but you should be doing it on the $output in the template for the field that you've got set to 'exclude' and are grouping on.
Comment #5
sprior commentedI thought the $output contained the final rendered version which would include the field label, so I was guessing that I should use the data that was used to build up the $output in the first place and then print that.
Comment #6
merlinofchaos commented$output does not include the field label, that is printed separately.
Comment #7
sprior commented