Panels 2: Create a node override

Last modified: December 4, 2008 - 09:23

Drupal's built in content viewing is decent, but sometimes (especially with custom content types) you might need a special way of displaying that content. If you want some basic layout tools, you can very quickly create specific layouts for specific content types with Panels 2. Let's try it, creating different layouts for pages and stories.

  1. Add a panel with the following settings:
    • Panel name: node_override
    • Page title: '%node'. This will feed in the title of the actual node we're overriding.
    • Path: node/%
  2. Now go to the 'Context' tab, and under the 'Arguments' section, select 'Node ID' and click 'Add argument'.
  3. In the modal dialog, select the content types 'Page' and 'Story', and select them again under 'Own display'. This will allow you to modify the node presentation for just these content types (and separately if you choose, as we are doing). Content types you don't select here will bypass the panel display completely and display as regular nodes. Click 'Save' at the bottom of the window.
  4. Click 'Save' at the bottom of the page.
  5. Click the 'Content' tab at the top.
  6. Since we want different displays for different content types, we aren't using the 'Default' tab. So let's click the 'Node ID 1 Page' tab for now. That will edit the page node override.
  7. For the 'Page' content type, let's have an override that shows the content on top, the comments on the middle left panel, as well as some text and a comment add form on the middle right. The bottom won't be used, but don't worry, Panels 2 ignores the parts that aren't used. The first thing to add is the content:
  8. Click the plus sign icon in the top section of the panel.
  9. Under the 'Node context' heading, find and select 'Node content'.
  10. Click the 'Link title to node' checkbox.
  11. Click 'Add pane' at the bottom of the window.
  12. Ok, now for the left side. Click the plus sign on the left section of the panel.
  13. Under the 'Node context' heading, find and select 'Node comments'.
  14. Click 'Add pane' at the bottom of the window.
  15. And on to the right side; click the plus sign on the right section of the panel.
  16. Under the 'Custom' heading, find and select 'New custom content'.
  17. Set the Title to: Comment Policy
  18. Set the Body to:
    Please use our comment system responsibly; and don't flame! We're a happy community here.
  19. Click 'Add pane' at the bottom of the window.
  20. Click the right plus sign again.
  21. Under the 'Node context' heading, find and select 'Comment form'.
  22. Click 'Add pane' at the bottom of the window.
  23. Click 'Save'.
  24. And now we have a page override:
  25. Now, on to the node override for Stories. Let's have something similar to our page node override, but with the content and comments on the left, and the comment policy and comment add form on the right. Nothing will be on the top this time.
  26. Click the 'Node ID 1 Story' tab at the top.
  27. Click the plus sign on the left.
  28. Under the 'Node context' heading, find and select 'Node content'.
  29. Click the 'Link title to node' checkbox.
  30. Click 'Add pane' at the bottom of the window.
  31. Click the plus sign on the left again.
  32. Under the 'Node context' heading, find and select 'Node comments'.
  33. Click 'Add pane' at the bottom of the window.
  34. And on to the right side; click the plus sign on the right section of the panel.
  35. Under the 'Custom' heading, find and select 'New custom content'.
  36. Set the Title to: Comment Policy
  37. Set the Body to:
    Please use our comment system responsibly; and don't flame! We're a happy community here.
  38. Click 'Add pane' at the bottom of the window.
  39. Click the plus sign on the right side again.
  40. Under the 'Node context' heading, find and select 'Comment form'.
  41. Click 'Add pane' at the bottom of the window.
  42. Click 'Save'.
  43. And now we have a page override:
  44. You are now done with this tutorial, but remember, this can apply in a ton of ways to any content type.

If you want to import a starting point, download the code and import it by clicking the import tab at the top of the Panel pages module.

AttachmentSize
panels_2_create_a_node_override_code.txt6.66 KB

Node overrides can only be applied to Drupal node addresses

takinola - November 16, 2008 - 05:35

When creating a node override, you may only override the original Drupal address (e.g. node/*/edit, taxonomy/term/*) and NOT any aliases of the original address. This kind of makes sense when you think about it but if you have pathauto generating aliases automatically, it is easy to forget that those addresses are not available to Panels for override

Actually, in Panels for

aaron - December 4, 2008 - 03:45

Actually, in Panels for Drupal 6, it will respect aliases, although you may need to visit your modules page to reset the menu.

Drupal Multimedia (my book)
AaronWinborn.com (my blog)
Advomatic (my work)

So this definitely doesn't

kwixson - February 11, 2009 - 23:45

So this definitely doesn't work for Drupal 5? I have to turn off pathauto?

EDIT: Hey, I just tried this on my Drupal 5 site and it overrides path aliases just fine.

node_override with custom content types made from CCK?

mattyboy - February 26, 2009 - 00:26

Hey there,

First of all, great tutorial, this is just the kind of thing I was looking for, and the step-by-step guide helped me follow along with ease.

I'm currently rebuilding my site (www.3photoshop.com) with drupal. I love what you're doing here in this tutorial with panels, but is there a way of overriding custom content types made from CCK? When I try to use this method to add CCK fields to a panel I don't seem to get the fields as options?

I'm just wondering if you can tell me why, or maybe point me in the right direction?

Many thanks

Matt

do you have these

idcm - August 10, 2009 - 13:30

do you have these instructions for D6 panels 2?

 
 

Drupal is a registered trademark of Dries Buytaert.