Community Documentation

Embedding Multiple Views and Creating Panel-Like Pages in Quick Tabs

Last updated February 11, 2011. Created by stongo on February 11, 2011.
Log in to edit this page.

In looking for a way to create quick tab content that emulated panels-like content, I had first created a node and using the php input filter, embedded views using views_embed_view(). This however was a major performance concern, as the php input filter is not cached, and stores the php in the database, using eval() to process it on node load.
A better solution is to create a custom block using hook_block, and store the block content in an include file. You can then set these blocks as your Quick Tab content.

Step 1

We need to add our block(s) to a module. I just added them to my site's custom module, mysite_custom. In your module, use the following code:

function mysite_custom_block($op = 'list', $delta = 0, $edit = array()) {
  if ($op == 'list') {
    $blocks[0] = array(
      'info' => t('My Quicktab'),
      'cache' => BLOCK_CACHE_GLOBAL, // You may want to change this setting. See http://api.drupal.org
    );
    return $blocks;
  }
  else if ($op == 'view') {
    switch($delta) {
      case 0:
        require_once('mysite_custom.qtpages.inc');
        $block = array(
          'subject' => 'My Quicktab',
          'content' => mysite_custom_qtabs_1(),
        );
        break;
    }
    return $block;
  }
}

Make sure you change "mysite_custom" to whatever your module is called. We're going to put our block content in an include file for optimum performance.

Step 2

Create a file called "mysite_custom.qtpages.inc"
In this file, here's the code to display our content.

function mysite_custom_qtabs_1() {
  $output =
  '<p>Some custom content goes here.</p>
  <div class="column-1">
    <h2>News</h2>' .
    views_embed_view('homepage_today', 'block_1') .         
  '</div>
  <div class="column-2">
    <h2>Events</h2>' .
    views_embed_view('homepage_events', 'block_1') .         
  '</div>';
  return $output;

This is of course just an example layout.

Step 3

In your Quick Tab settings, choose the block "My Quicktab" we created and you're off to the races.

I have three Quick Tabs using blocks all generated this way, and it is smoking fast and drastically reduces resource consumption.
Good luck!

Comments

For anyone interested in

For anyone interested in doing this in D7, here is the port that I got working...

<?php
module_load_include
('inc', 'sh', 'sh.qtpages');

function
sh_block_view($delta = '') {
   
$blocks = array();
    switch(
$delta) {
      case
0:
       
$block['subject'] = t('first');
       
$block['content'] = sh_qtabs_1();
        break;
     case
1:
       
$block['subject'] = t('second');
       
$block['content'] = sh_qtabs_2();
        break;
   
    return
$block;
  }

function
sh_block_info() {
 
$blocks = array();
 
$blocks[0] = array(
   
'info' => t('Articles Latest Tab'),
   
'cache' => DRUPAL_NO_CACHE,
  );
  
$blocks[1] = array(
   
'info' => t('Health Latest Tab'),
   
'cache' => DRUPAL_NO_CACHE,
  );
 
}
?>

Page status

No known problems

Log in to edit this page

About this page

Drupal version
Drupal 6.x
Audience
Developers and coders, Themers

Site Building Guide

Drupal’s online documentation is © 2000-2012 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.