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.
Comments
Populate quick tabs with fields when adding content
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?
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.
Create Quicktab block that is populated by cck fields
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-...
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 Namdhari
https://TajinderSinghNamdhari.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
What i need to add to display quicktab and its content
hi,
I'm writing below code in my node--story.tpl.php, but only empty page is loading when i load the node page.Can you please help in knowing my mistake.
What i need to add to display quicktab and its corresponding viewmode content?
第一位回答的不一定对,至少我在drupal6下面不是这样的
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)
A Project Ricochet, Drupal Developers Team Member
Set the default tab
In addition to
$quicktabs['hide_empty_tabs'] = TRUE;
You can also add:
$quicktabs['default_tab'] = 'featured_product';
A Project Ricochet, Drupal Developers Team Member
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
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:
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.
I get blank page
I try to use this code but I get a blank page. Since the change to machine name I can't get to render a QT using php code in a node.
I am using the machine name i get from the admin/structure/quicktabs .
Can someone provide some help please?
Thanks!
blank page
in my case I got a blank page because i use "Filter HTML" as Text Format in the contents of quicktab. It got it to work after I set them all to "Full HTML".
Another way of inserting into node template - Drupal 7
You can embed in your node template using following code in Drupal 7 :
*machine name can be found in admin/structure/quicktabs
I have tested in Drupal 7.21, it works.
This snippet of code worked
This snippet of code worked for me using D7! Thanks simone960!!
Thank you! This helped me a
Thank you! This helped me a lot! Tested on 7.32
This one works
This works perfectly for rendering quicktabs in tpl.
Quicktabs Field
I created a module that creates a field for quicktabs this might be useful for simple tabs. Quicktabs Field
Creating tabs and then rendering them
This worked for me (D7):
How did you alter the list
How did you alter the list classes for the tabs?
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.:
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:
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?
Worked for me
thanks