Adding a Quick Tab block to a node
Last updated on
30 April 2025
As stated in #332895: render quicktab programatically, it is possible to use the Quick Tabs API to add a Quick Tabs block directly to a node, or a template file.
There are several ways, listed below, to add a Quick Tabs block to a node. Choose whatever works best for you.
- Use the Insert Block module.
- Enable the PHP Input Format (which is a separate module in Drupal 6) and use either of the following code snippets
- Display a Quick Tabs block that has already been created.
- Create the Quick Tabs block programmatically.
- Enable the Quick Tabs block in the blocks admin page (admin/build/block), and set the visibility options to show only on the path of the node in question.
<?php
$qtid = 42; // write here your quicktabs id.
$quicktabs = quicktabs_load($qtid);
print theme('quicktabs', $quicktabs);
?><?php
$tabs['first'] = array(
'title' => t('One'),
'type' => 'view',
'vid' => 'my_view_id',
'display' => 'my_display',
'args' => 'my_arguments',
);
$tabs['second'] = array(
'title' => t('Two'),
'type' => 'block',
'bid' => 'modulename_delta_id', // e.g. user_delta_1
'hide_title' => TRUE,
);
$tabs['third'] = array(
'title' => t('Three'),
'type' => 'node',
'nid' => 'my_node_id',
'teaser' => TRUE,
'hide_title' => TRUE,
);
$tabs['fourth'] = array(
'title' => t('Four'),
'type' => 'freetext',
'text' => 'Hello World',
);
$quicktabs['qtid'] = 'any-unique-id';
$quicktabs['tabs'] = $tabs;
$quicktabs['style'] = 'Excel';
$quicktabs['ajax'] = FALSE;
print theme('quicktabs', $quicktabs);
?>Note that this method may not be as flexible as you need, depending on the regions provided by your theme.
As stated in #332895-13: render quicktab programatically, it is also possible to render a Quick Tabs block in the theming layer, but it is best done through a preprocess function. The following code example illustrates the technique:
function MYTHEMENAME_preprocess_page(&$vars) {
// As quicktabs require additional js and css files, we must construct the quicktab here.
$quicktabs = quicktabs_load(42);
$vars['myquicktab'] = theme('quicktabs', $quicktabs);
// Reconstruct CSS and JS variables.
$vars['styles'] = drupal_get_css();
$vars['scripts'] = drupal_get_js();
}
After doing this, you can simply use
print $myquicktab
in your theme.
Help improve this page
Page status: Not set
You can:
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion