You are here

Displaying node fields in sidebar blocks (without panels)

One thing about Drupal that may annoy content editors, who do not have very many permissions, is that they can edit the inside content (Body) of pages that they manage, but they cannot create and edit blocks without the full 'Administer blocks' permission.

Here's the setup I have used (in many variations) to give page editors access to creating and editing blocks on a page.

Create the field, whose content will be pulled into a block

On your regular 'Page' content type (or whichever content type you want to have an easily editable side block), add a brand new field with 'Long text' as the type.  I've called my new field 'Sidebar Info'.  Just make the title clear enough that your editors will easily understand this to be the field that will appear as a side block.

Side block field
(Click on image for full view)

When this field is filled in, we will not display it as a field in the regular content area, we will rather pull it into a block and display it on the side.  So, in the 'Manage Display' settings for the content type, make sure you mark this new field as 'Hidden'.

Create the view, which pulls the sidebar field content

Side block view screenshot
(Click on image for full view)

The view should be of type 'Block' and I've circled and highlighted the most important aspects of the view in the screenshot above.

The trick is to use a contextual filter of 'Content: Nid'.  This means that when this block view is displayed on any node page (verses view page, for example), it'll pull in the nid of that node and associate any fields it's trying to pull in with *that* node.  Make sure you setup that contextual filter to pull in the nid from the URL by default:

Finally, as you can see, the only field I'm pulling into the view to display is the 'Sidebar' one we created earlier. 

Place the new block on the sidebar of necessary pages

To place this new block on the necessary pages, you can either create a context (my chosen method) or do it with panels or the regular block administration page.

You can simply create a new context which is active sitewide or for certain content types and place the new block view (View: Page Slideshow Block: Block: Sidebar) in the block region you want: in my case, 'Second sidebar', but each theme names these regions differently, so this will be unique for you.

Let's test!

Go ahead and create a brand new Page (or whatever content type you created your side block field on), and fill in the new field

As soon as you save the page, the content from that field should appear not in the content section, but, dutifully, pulled into a block on the side (or whatever region you placed it in):

Of course, I've styled the block here, and yours will be plain if you haven't done any theming yet.  However, you notice that I have a special class applied to the block via the created view, which I use for styling. So you can use that approach too.

 

Share

Comments

Just when you think you understand something, you realise you don't. What a marvellously elegant and simple way to solve a problem I had never really thought about before until tonight. Thanks for the blog post. Really saved my bacon :)

I'm so glad it was helpful!  Thanks for the comment!

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.