Skip to main content
lightbox2 with nodes

Display nodes with Lightbox2

Lightbox a powerful module in Drupal arena., proved its mastery once again! I was involved in trying to find a way to display nodes in popup, the apparent module that struck my way was Colorbox-Node. Things looked as if it would be a cake-walk but went beyond what I thought. The Colorbox-Node holds the ability to display nodes in overlay effect, but it needs huge template and jQuery level customization. All my assay went in vein, there came Lightbox to rescue.

No prelude to Lightbox is required to Drupal developers, but for newbie., It is a Module that can produce overlay/ popup effects to your site. Let me not deviate, the following steps were followed to Load a node in Lightbox.

1. Identify the template file using devel_themer or in case of Views use Advanced->Theme->information.

2. In my case I was using views to display the images associated with the nodes. On clicking the images It would show the full node in the Lightbox.

3. Add '/Lightbox' to the href and 'Lightframe' to the rel. It would look like

<a href= "node/<?php print $row->nid;?>/lightbox" rel="lightframe">

4. Save the Template file and clear the cache to see the node being loaded in Lightbox.

To extend further: 

I had no need to display the sidebars, headers in the lightbox. Hence I wanted to remove these regions in the template files. Was a catch22 again because the Page-node.tpl.php was a common file. Any removal of regions will reflect in the full node view as well.

The thought to use a template based on content type struck as an idea. In my case only one content type was to be shown in lightbox, hence I moved further with my idea with no hesitation. 

Place the below mentioned code in template.php in themes folder and create a template file called page--content-type.tpl.php, all nodes with that type will use the new template file.


 
  1. function yourthemename_preprocess_page(&$vars) {
  2.   if (isset($vars['node']->type)) {
  3.     $vars['theme_hook_suggestions'][] = 'page__' . $vars['node']->type;
  4.   }
  5. }
  6.  
 

 

Comments

ipwa (not verified)

Sat, 10/13/2012 - 18:36

I used to use Lightbox2 in Drupal6 but prefer Colorbox in Drupal 7, it's a lot lighter and looks better (to be fair both can be themed and I do love Lightbox2 because some of my patches like the alternate display where committed). Colorbox-node, really saves me time using Colorbox to display nodes in overlays, no messing about with templates. I don't understand the line ''it needs huge template and jQuery level customization".

I used both the modules (lightbox and colorbox) for content display in popup. Unfortunatly I couldn't get the result.Above, step-3 is not clear. Where is this exactly? How can I get the popup for a node content?Thanks

Add new comment

The content of this field is kept private and will not be shown publicly.

Plain text

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