Community Documentation

Adding a Quick Tab block to a node

Last updated July 2, 2010. Created by jdwfly on January 8, 2010.
Edited by EvanDonovan, budda. Log in to edit this page.

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:

<?php
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

<?php
print $myquicktab
?>

in your theme.

Comments

Hello!
I have a lot of product-pages that all have a QT-block in the content-bottom. Now I populate the two tabs with plain text that i fill in by adding new blocks and then populating the qt-block with these two new blocks. So when adding a product i have to first create the product, then create the two blocks, then create a qt-block with the two new blocks as tabs, then activate the new QT-block for only the product-page I just created. This takes a lot of time, and is not user friendly.

The thing I should want to do is the following:
Add two fields with CCK to the node-type product. Then, when I fill in the two fields when creating a product, they should automatically appear as a QT-block below the content.

Is this possible with QT, or should i have to hide and present the two fields with javascript in the theme instead?

--
working at Genero, Making Drupal websites and templates, My blog: Jonathans blog

Hi Jonathan! You can

Hi Jonathan!

You can do that rather easily. First you disable or hide the CCK fields in the content types field visibility settings. After that you have to create a little module that implements hook_block(). In that module you check if arg(0) is 'node' and if arg(1) is numeric. If so, you can do a node_load(arg(1)) and receive the currently shown node page. After that you might check if the node's type is correct (you don't want to show empty quicktabs on other content type's pages).

Following above's code snippet for programatically creating quicktabs you can now get the cck fields' values out of the node, add some HTML around and put it in a freetext tab. The themed quicktab output is what your YOURMODULE_block() function actually returns when viewed.

Another solution without having to code may be using the CCK Blocks module which lets you create blocks to show node's CCK fields. These you may also use as quicktab tabs and you could then set the quicktab block into a node bottom or content bottom region of your theme. But I haven't tested the latter approach myself.

Thank you Webseiter, I just figured out how to do it myself, and the funny part is that it is very close to your solution! I made two new blocks, I pulled the cck-fields to the blocks with php, i made a quick-tab that is only shown on my product pages (that's where I needed the tabs), and I populated the tabs with the two blocks that I made before. I made an article describing how I did, just tell me if you think I should have done something in another way. :)

http://jonathanbjorkskog.com/create-quicktab-block-that-is-populated-by-...

--
working at Genero, Making Drupal websites and templates, My blog: Jonathans blog

Wonderful, This code sample's

Wonderful,

This code sample's 2nd point really saved me....

I had to generate quicktabs for content being generated randomly using a views and further call another view being content of that quicktabs block.

Thanks a lot for posting.

Best Regards,

Tajinder Singh
IMP Technologies
Creating Masterpieces...
http://imptechs.com

node template

Instead of enabling the PHP Input Format I would suggest to use custom node template to display the quicktab.

for story content type use node-story.tpl.php

<?php
$qtid
= 42; // 这个地方在drupal6下面应该用你在后台建quicktabs时使用的机器读的machine_name而不是qtid
$quicktabs = quicktabs_load($qtid);
print
theme('quicktabs', $quicktabs);
?>

Hiding empty tabs.

Doesn't look like this is clearly documented, but you can add $quicktabs['hide_empty_tabs'] = TRUE; to hide empty tabs (views, blocks, freetext, etc)

Set the default tab

In addition to
$quicktabs['hide_empty_tabs'] = TRUE;
You can also add:
$quicktabs['default_tab'] = 'featured_product';

<?php
        $quicktabs
['qtid'] = 'product-tabs';
       
$quicktabs['tabs'] = $tabs;
       
$quicktabs['style'] = 'sky';
       
$quicktabs['hide_empty_tabs'] = TRUE;
       
$quicktabs['ajax'] = FALSE;
       
$quicktabs['default_tab'] = 'featured_product';
        print
theme('quicktabs', $quicktabs);
?>

how can i achieve this on drupal 7?

How can i achieve this on drupal 7 I need to put the tabs on one node.

Try to insert a code like

Try to insert a code like this in a node

<?php
$tabs
['tab1'] = array(
 
'title' => t('tab1'),
 
'type' => 'node',
 
'nid' => '122'// write here the id of the node you want display
 
'teaser' => FALSE,
 
'hide_title' => TRUE,
);

$tabs['tab2'] = array(
 
'title' => t('tab2'),
 
'type' => 'node',
 
'nid' => '123',
 
'teaser' => FALSE,
 
'hide_title' => TRUE,
);

$quicktabs->machine_name = 'tab-serie';
$quicktabs->tabs = $tabs;
$quicktabs->style = 'Excel';
$quicktabs->ajax = false;
$quicktabs->hide_empty_tabs = 1;
print
render(quicktabs_render($quicktabs));
?>

now it is better to use the 7.x-2.x-dev version rather than the 7.x-2.0-beta1 version.

7.x-3.0-beta1

I use 7.x-3.0-beta1.
To insert it in a node, I use something like this:

<?php
// in 7.x-3.0-beta1, it uses name not id
// quicktabs name available in admin interface: admin/structure/quicktabs
$qtname = 'first_quicktab';
print
drupal_render(quicktabs_build_quicktabs($qtname));
?>

Drupal 7 custom quicktabs

if someone wants to render quicktabs without storing it in database it is still possible.
check the quicktabs_build_quicktabs() function.

Quicktabs Field

I created a module that creates a field for quicktabs this might be useful for simple tabs. Quicktabs Field

Wonderful!

Wonderful!Thanks.

Using D6 this only worked for

Using D6 this only worked for me if I put this code in MYTHEME_preprocess_node($&vars), in case anyone is banging their head, although I'm not sure if this code should really be in page_preprocess.:

<?php
$vars
['styles'] = drupal_get_css();
$vars['scripts'] = drupal_get_js();
?>

Just first quicktab tab title displayed? Solution

I did all of the above for D6 in various different ways just for 3 tabs of freetext "TAB 1" thru "TAB 3". Custom modules, pre-process page and node and then eventually in template.php. Each time all I was seeing was the tab title of the first tab; "TAB 1". The HTML looked fine. I had the JS and CSS already on the page for a "proper" quicktab block.

In the end all I needed to do was surround the quicktab in
<div class="block block-quicktabs">...</div>

Stupidly simple, but not mentioned anywhere. Hopefully of help to somebody.

How can we pass more than one

How can we pass more than one argument to the Views in a tab? I have tried array(...) and it didn't work (D6)

use the same format as the argument is used in url

"excessive" example:

<?php
$tabs
['first'] = array(
 
'title' => t('One'),
 
'type' => 'view',
 
'vid' => 'my_view_id',
 
'display' => 'my_display',
 
'args' => 'arg1/arg2/tax1+tax2+tax2/tax1,tax2,tax3',
);
?>

the example is nothing special, it is how views module uses arguments (contextual filters):
/ argument separator
+ OR (for 1 argument with multiple values)
, AND (for 1 argument with multiple values)

Drupal 6 tabs in a node to link in another node

$tabs['third'] = array(
'title' => t('Three'),
'type' => 'node',
'nid' => $myothernode,
'teaser' => TRUE,
'hide_title' => TRUE,
);

When using your example in node-myName.tpl.php, it seems to fail to load another node into a node tab view.
Am I doing this wrong or what?

Page status

No known problems

Log in to edit this page

About this page

Drupal version
Drupal 6.x
Audience
Developers and coders, Site administrators, Site users, 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.