Skip to main content
program to creating QuickTab

Drupal - programmatically creating QuickTab using custom code

QuizTabs  module is a very nice addition to bunch of drupal modules. This module allows you to create blocks of tabbed content, specifically views, blocks, nodes and other quicktabs. I had a different requirement where I needed to use dynamically generated content in different tabs. I ended up in creating quicktabs content from code. 
Lets 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 advace. For True it will load dynamically on clicking the tab


Sample output