views:

114

answers:

1

Hi there!

I have a few views in my Drupal site that are getting extremely out of hand... The views show nodes from different content types in the same listing, and are formatted differently depending on the content type... This has so far required a lot of custom PHP-fields, rewriting output, and a bit of black magic. Totally unmaintanable code. :)

So, what I'm looking for is a module, or a technique, or a hack, to more gracefully make different content types and their CCK fields show up in the same listing.

Here's a pseudoexample:

Video node: Node Title Embedded video field Comment count

News article node: Custom CCK title field Node body Comment count but with rewritten output to insert a div class or something

For this example in my current layout, I would add node title to fields but exclude it from output, then outputting it in a php customfield with an if-statement, same with node body (since both node types have titles and bodies but only one of the two types should display it). Comment count would be added twice, then I'd exclude both and output them again through a custom php-field with a switch-statement for content types... Ugly, huh?

Any advice on modules, hacks or better design choices are welcome. :)

+1  A: 

It sounds like you are trying to do what the theme layer does but in the views admin.

Go back a little, switch to node view and then create a template in the format node-view-VIEWNAME.tpl.php (as explained here)which handles the display logic for all nodes likely to be pulled in by your view.

This will encapsulate all of your display logic for the view in a single template, and save you from having to do hacks in the other display templates or in your view itself.

If you need help getting the template to be picked up then let us know, but it seems like you know what you are doing.

Jeremy French