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

merlinofchaos’s picture

Status: Active » Fixed

You 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.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

sprior’s picture

Status: Closed (fixed) » Active

merlinofchaos, 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?

merlinofchaos’s picture

Status: Active » Fixed

You'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.

sprior’s picture

I 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.

merlinofchaos’s picture

$output does not include the field label, that is printed separately.

sprior’s picture

Status: Fixed » Closed (fixed)