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.

  1. Use the Insert Block module.
  2. Enable the PHP Input Format (which is a separate module in Drupal 6) and use either of the following code snippets
    1. Display a Quick Tabs block that has already been created.
    2. <?php
      $qtid = 42; // write here your quicktabs id.
      $quicktabs = quicktabs_load($qtid);
      print theme('quicktabs', $quicktabs);
      ?>
    3. Create the Quick Tabs block programmatically.
    4. <?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);
      ?>
  3. 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.
  4. 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: