• RESUME
  • LOGIN

balanced scale media

  • blog
  • projects
  • services
  • contact
Home › Blogs › boz's blog

Nid Based Panel Variants in Drupal

boz — Tue, 03/09/2010 - 20:47

For one of my recent projects, I had the privelege of learning how to use the Drupal panels module.  I needed a panel that swapped out content based on which page I was on.  Here is how to do it:

  1. Install Panels
  2. Go The Panels Admin Page in your Drupal install and instead of Creating a new panel, edit the Node Template.
  3. Click the "Add Variant" button
  4. Give the Variant a Title, check the "Selection Rules" box in the options, and click "Create Variant".
  5. Define a Selection Rule of type "Node Type" and set it to page. (You only want the panel responding to Page nodes)
  6. Define a Selection Rule of type "PHP Code".
  7. In the PHP Code text area paste "return arg(1) == 2;" replacing the "2" with the nid, or node id, of the page that you want this panel variant to show up on.
  8. Click "Continue"
  9. Choose your layout.
  10. Add Content to each panel area in the layout that you chose. (Click on the gear icon in each panel and select "Add Content")
  11. Click "Update and Save"
  12. Repeat steps 3-11 for each page.

Note that the order of the variants is important.  You can think of the vertical list of variants for the panel as a switch statement.  This means Drupal will check if the first variants selection rules match and move on to the next if they do not.  However, if they do match then it ignores the rest of the variants.  This was confusing to me until I figured out how it worked.  This could be leveraged if you want to used a default variant whose selectoin rules are more broadly satisfied.

  • Drupal
  • boz's blog
  • Add new comment

Recent Posts

  • Generate Word Documents With PHP
  • Delete CCK Inactive Fields
  • Delete Nodes From A Certain Date in Drupal
  • Automated Node Titles Without Auto Node Title
  • Drupal Camp Iowa Ajax Example
  • Get Paid To Learn Drupal!
  • Presenting "JavaScript Guidelines : When and When Not to Script"
  • Drupal Form Alter on a Node Reference Widget
  • The Paradox Of Drupal
  • Programmatically Creating Users in Drupal with Profile Fields
more

Topics

  • Android
  • Apace
  • Aptana
  • Bazaar
  • Browser
  • Code
  • Drupal
  • Eclipse
  • Flex
  • HTML 5

Archive

  • February 2008 (1)
  • May 2008 (1)
  • July 2008 (3)
  • December 2008 (2)
  • January 2009 (2)
  • March 2009 (3)
  • April 2009 (5)
  • May 2009 (1)
  • July 2009 (1)
  • August 2009 (3)
more

Links

 

  • blog
  • projects
  • services
  • contact

© 2012 Balanced Scale Media, LLC. All Rights Reserved.