Drupal: Complex View Layout, Getting Down and Dirty!
- Tuesday, April 6th, 2010 -
Drupal provides a ton of great functionality, but every now and then you get a designer, Amber
, who just try’s to come up with a design for a Drupal site that challenges your knowledge of the system. Well thanks to the challenge I have found a nice bit of functionality to allow very custom views.
My challage was to have a block created by a View, pull the top 3 news nodes (basically like a blog) and display it on the homepage side-bar. Well that is not difficult, I even created a template for the block. Well now we wanted to show additional data for the first item in the view and not for the rest.
Question: Well, there is not a loop or counter to check for in the template file so how was I to get this done?
Answer: Using a Views Attachment Display.
Drupal Views have a display type called attachment. It is exactly as its name sounds, a view that attaches to another. You can set it to display the additional data that you would like to display for the first item(or how ever many you want) then tell the Attachment Display to display before/after another View. Just change the offset of the main view to compensate for the items brought in by the Attachment.
Hope this helps others.
