11

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.

3
  • Which version of Drupal?
    – keva
    Jul 12 '11 at 22:03
  • Sorry, this is for Drupal 7. I've added that info to my original question. Jul 12 '11 at 22:37
  • I'll accept an answer as soon as I get to addressing the problem. I'm currently figuring out how to setup my suggestions to display content appropriately... Jul 13 '11 at 14:45
11

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.

5
  • 1
    The views/block approach is actually the one I prefer, but suggested Display Suite since some find it more approachable.
    – jhedstrom
    Jul 13 '11 at 0:26
  • Views works great for this, as I'm discovering. Views is fantastic in general. I also use the Menu Block module to split up my menus based on where I am in the site (let's me split up the main menu so it's always showing, and the sub menus based on what menu I fall under in the main menu). Totally awesome module, highly recommended. Jul 21 '11 at 14:41
  • Kind of crazy that I asked this almost a month, accepted the answer, but am just getting to the application of this answer now (though I've used Views a ton since). Could you clarify your use of Views a little bit for Drupal 7? It appears that Argument: nid does not exist in Views 3 for Drupal 7. Thanks. Aug 10 '11 at 18:11
  • I figured it out. The notion of Argument has been replaced by Contextual Filters under Advanced. Aug 10 '11 at 18:29
  • D7, Contextual Fitler: Content: NID. Edit: see you found it, before I could answer
    – iStryker
    Aug 10 '11 at 18:41
7

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

5

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
    }

2
  • 1
    This answer is super-ultra-clever, and doesn't require any external modules, other than to define view modes. Simple alternative to Display Suite is Entity View Modes: drupal.org/project/entity_view_mode
    – paul-m
    Jan 20 '12 at 20:17
  • I really liked this one. Wrap it in an if function to only have it appear on certain pages. I used if (array_key_exists('block_14',$vars['page']['main_content'])){} to make it only appear on pages with a specific block. Sep 2 '13 at 12:23
3

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).

0
1

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.

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.