blog-banner

Drupal - Programmatically Creating QuickTab Using Custom Code

  • Drupal 6
  • Drupal 7
  • QUICKTAB

Drupal QuickTabs

 
QuickTabs module is a very nice addition to a bunch of drupal modules. This module allows you to create blocks of tabbed content, specifically views, blocks, nodes, and other quick tabs. I had a different requirement where I needed to use dynamically generated content in different tabs. I ended up creating quick tabs content from code.
 
Let's assume, we have a page and content is generated from code something similar below,
 
$tabs = array();

$tabs[] = array(
  'title' => t('Tab1'),
  'type' => 'freetext',
  'text' => 'Hello wecome to Tab1',
);
$tabs[] = array(
  'title' => t('Tab2'),
  'type' => 'freetext',
  'text' => 'Hello wecome to Tab2',
);
$tabs[] = array(
  'title' => t('Tab3'),
  'type' => 'freetext',
  'text' => 'Hello wecome to Tab3',
);
 
Now time to render the tabs.
 
$quicktabs['qtid'] = 'QUICKTAB_NAME'; // custom name
$quicktabs['tabs'] = $tabs; // refer our previous code block
$quicktabs['style'] = 'Zen'; // style name 
$quicktabs['ajax'] = FALSE;
print theme('quicktabs', $quicktabs); // theme of quick tabs.

qtid  - is the unique tab id.

tabs - contains the actual tab content

style - various styling available for quicktabs. EX: Basic, Arrows, Bullets, Excel, Phylactere & etc.

ajax - False represents that all content will be loaded in advance. For True it will load dynamically on clicking the tab.

 
Get awesome tech content in your inbox