Question

My situation is as follows: I have a content type Seminar, with fields A, B, and C. I have regions Header, Footer, Content, and Sidebar Left. There are some fields in Seminar I want displayed in the Content region, but also in the Sidebar Left region.

How do I go about doing this? Apologies if this has already been answered before. I am a developer and am not hesitant to dive into hook and preprocessor functions. I have the Views module installed, but have never used it (this is my first Drupal site, if you can't tell :P).

Cheers.

EDIT: This is for Drupal 7.

Was it helpful?

Solution

There is no easy out of the box way to add the content of a node to different regions on the page. There is multiple ways to tackle this problem.

Non-coding way: Views & Blocks

Create a view

  • Type: Block
  • Contextual Filter: Content: Nid
    • default value: grab from current page
  • Fields: Whichever you want
  • Filter:
    • Content Type: Seminar

(plus whatever additonal settings you want)

Then go to administrator block page Move the newly create view block, to the region you want it displayed. It should only display on the seminar node pages.

Repeat for all regions

Coding Way with theme_preprocess_region():

code would look something like this

MYTHEME_preprocess_region(&$variables) {
  if (isset($node) && ($node->type == 'seminar' )) {
     //add new variable here.     
  }
}

This is for Drupal 7 only. Now its avaiable in your region.tpl.php.

OTHER TIPS

The Display Suite module allows you to do this. You'll need to enable the Display Suite Extras module to expose theme regions as targets for node components. Information on how to do this can be found in the Add fields to a block page of the Display Suite documentation

I've had the same problem. The solution is quite easy. You can base the fact that in Drupal 7 we can define our own view_mode, not only FULL and TEASER (as we know from oldest versions). So, define another view_mode for using in your region: e.g. LEFTHAND. Drupal displays FULL view_mode in content region. So, you have to say to Drupal to display LEFTHAND in Sidebar Left region.

  1. In template_preprocess_page()

    if ($vars['node']) {
    $vars['page']['sidebar_left'][] = node_view($vars['node'], 'lefthand');
    }

  2. In node.tpl.php add a new display for lefthand view mode

    if ($view_mode == 'lefthand') {
    // render content fields here
    }

If Display Suite seems like too much for you needs (It is a great module, but it might be overkill if you just need to relocate a few fields) there is a module for only this purpose -> CCK Blocks.

I know it is called 'CCK' blocks, but it works with Drupal 7 (which brought the functionality of CCK to the core).

Slight change to @Patrik Lucan's answer, if ($vars['node']) was causing me problems on pages which weren't nodes, e.g. custom front page with block or views page.

Changed to:

if (array_key_exists('node', $vars))

Which seems to have solved the problem.

Meanwhile there's a module for this. From the module page:

Field as Block provides an easy way to display one or more fields of the current node in a block.

This module aims to be a light weight alternative to modules like Panels and Display Suite, or using Views to define a block which only retrieves one field.

Licensed under: CC-BY-SA with attribution
Not affiliated with drupal.stackexchange
scroll top