Changing views output based on row

Submitted by Brandon Cone on 07/16/2013 - 03:05:pm

When you're creating a view which will serve as a landing page or news aggregator, sometimes it's nice to be able to hightlight certain pieces of content (maybe new ones) while letting others fall into more of the "news feed" format.  I found myself needing this recently for a client and was fortunate enough to have sat in on a session about Display Suite at this year's Drupalcon.  Click Here for a screenshot of what we wanted to accomplish.  If you're like me, you've done things like this before but had to cobble multiple views together and put them on the same page using context.  This is feasible but quickly breaks down when start thinking about how to make sure all but the newest item shows in one view, etc.  

This is why I was so happy to have sat in on the aforementioned session.  I learned that you can configure exactly this output using one page view (which then allows you to use pagers more cleanly) using Display Suite's views row formatter.  

I'll try to outline the process as quickly as possible so that this doens't become too cumbersome of a post.
  0.   Before starting, it should go without saying that to use a Display Suite view formatter you'll need to
      have Display Suite installed on your site.  

  1. Configure your display modes.  Display Suite allows you to create display modes through the site so no need for custom code here.  Simply create the Display Suite Display Mode (mine was called first_item) and configure it to display according to your design.
    1. Chances are you'll want at least two display modes so don't forget to configure both according to your designs.
  2. Create your view.  As mentioned earlier, Display Suite is a display formatter so make sure you have your view set up to show "Display Suite" instead of "Fields" or "Content", etc.  
  3. Configure your Display Suite settings to set the display mode for items in the view.  In my example, I was only showing 3 items on a page so when you look at my screenshot, you'll see that there are only 3 rows which I can configure.
    1. There are a coule things to be aware of to make sure this works.
      1. The checkbox for "Use Changing View Mode Selector" needs to be selected.  If not, the default view mode will be the only one displayed
      2. You need to decide how subsequent pages will look (if you're using a pager).  Do you want them to all use this format or just show the default?
  4. Save your view.  I know it sounds like there should be more to it than this but it really is that simple.  If you want to change which fields are displayed in that view then you do all that by adjusting the display configuration for that view mode.  

Happy Site Building!