JStools.module, tabs.module - How do I use an include file?
I am currently attempting to do something that as of yet I'm not sure is even possible. I'm using the following setup to initialize jquery tabs in a test module I am working on:
<?php
function idkfa_all() {
$form = array();
$form['example1'] = array(
'#type' => 'tabset',
);
$form['example1']['tab2'] = array(
'#type' => 'tabpage',
'#title' => t('Two'),
'#content' => include('tab.two.inc'),
);
$form['example1']['tab1'] = array(
'#type' => 'tabpage',
'#title' => t('One'),
'#content' => t('First tab content.'),
);
$form['example1']['tab3'] = array(
'#type' => 'tabpage',
'#title' => t('Three'),
'#content' => t('Third tab content.'),
);
return tabs_render($form);
}
?>the contents of tab.two.inc is simply:
<?php
print "Hi, I'm tab two! Nice to meet you!!";
?>What ends up happening is that the "Hi, I'm tab two! Nice to meet you!!" appears at the top of the browser window "outside" of the template (I'm simply using the default Garland theme at the moment) and a "1" ($index) appears in the contant body for the second tab... regardless of the selected tab the contents of the include is show at the top of the browser.
By the way, anyone happen to know why the tabs have to be in the order as shown in the snippet above in order to show up in order (One, Two, Three, etc)??
Thank you,
Dixen

Print is not captured
Print will not work as you want in this context without using the buffer functions. Replacing 'print' with 'return' might work though I have never tried that. Seems like an odd use of include.
Fantastic!!
I've been in the irc channels for several hours now and noone else could help me out with this one... thank you very much as your solution fixes the problem.
As for the odd use of include... the project that I have this in mind for will be one that has 10-12 tabs, each with it's own content that could change from time to time. I figured working with a smaller include file instead of horking up one big one is far preferable.
Thank you again for you help...
P.S. Any ideas on the tab order thing? The tab in the second position always shows first... just odd I say!
On tab order and a thought
I can not reproduce the problem with the tab order (mine show in the order specified). Maybe it is related to the include, if you use a string for the content does the problem still exist?
And a though regarding the use of include. Since Drupal is a CMS you may want to consider making the content of the tabs be nodes, that way you can manage the content with Drupal and also gain the functionality that comes with nodes. So you might have something like (note, nids are for illustration only, you would need to pick real ones)
function idkfa_all() {
$form = array();
$form['example1'] = array(
'#type' => 'tabset',
);
$form['example1']['tab1'] = idkfa_make_tab(58);
$form['example1']['tab2'] = idkfa_make_tab(59);
$form['example1']['tab3'] = idkfa_make_tab(60);
return tabs_render($form);
}
function idkfa_make_tab($nid, $title = NULL) {
$node = node_load($nid);
$output = node_view($node);
if ( ! $title ) {
$title = $node->title;
}
return array(
'#type' => 'tabpage',
'#title' => $title,
'#content' => $output
);
}
?>
Very cool idea...
On the tab order, yes... regardless of whether the content for the second tab is a string variable or include it's still out of order. I keep looking for a comma or *something* that is out of place and have come up empty thusfar.
The tab loading idea is very, very nice indeed... it won't work for the specific project that I started with this in mind ... but it *WILL* fit the need for two other projects that I have on the back burner.
Thank you again for your thoughts and idea!!
Tab Order Issue
I'm having the same problem with the order of tabs showing up incorrectly. I'm trying to do something pretty basic...the third tab goes first, then the second, then first, the 4th, 5th and 6th...
Even w/ the tabsexample module! http://www.writingmatters.org/tabsexample
Must be related to another module I have installed right?
tab order, weight
I was able to answer my own question here, so I'll share it back. You can control the order of the tabs by adding '#weight' => '-10', under the title of the tab. Here's an example:
<?php
$form = array();
$form['example1'] = array(
'#type' => 'tabset',
);
$form['example1']['tab1'] = array(
'#type' => 'tabpage',
'#title' => t('First Tab'),
'#weight' => '-10',
'#content' => t('First Tab Content'),
);
$form['example1']['tab2'] = array(
'#type' => 'tabpage',
'#title' => t('Second Tab'),
'#weight' => '-9',
'#content' => t('Second Tab Content'),
);
return tabs_render($form);
?>
Dude you rock! I've been
Dude you rock! I've been trying to get nodes to load in my tabs for like 10 hours now. I'm on Drupal 5.7 and I can't believe no one else is trying to do this, or that I'm too retarded to figure it out. Either way, thank you so much.
For anyone following this here is the complete code that works on my installation.
<?php
function load_nodes_in_tabs() {
$form = array();
$form['example1'] = array(
'#type' => 'tabset',
);
$form['example1']['tab1'] = node_to_load(265);
$form['example1']['tab2'] = node_to_load(136);
return tabs_render($form);
}
function node_to_load($nid, $title = NULL) {
$node = node_load($nid);
$output = node_view($node);
if ( ! $title ) {
$title = $node->title;
}
return array(
'#type' => 'tabpage',
'#title' => $title,
'#content' => $output
);
}
print load_nodes_in_tabs();
?>
Note that the only thing I changed was the function name "idkfa_all" to "load_nodes_in_tabs" and "idkfa_make_tab" to "node_to_load". I also changed the numbers in the node_to_load(xx) function to actual nodes on my site.
Hope this helps someone.
Tim
Thanks for a starter in getting Tabs to at function
Thanks heaps for some code that's starting to work a little for me.
I thought getting Tabs to function was going to be a lot easier than what it has been. From a newbie POV, it's been rather difficult from a lack of documentation and examples - not everyone is a coding genius so thankfully I eventually stumbled across your example.
Should this example also work for views and any sort of other node? I'm getting this error and can't understand why it is:
warning: Invalid argument supplied for foreach() in /home/rastarr/public_html/lcm/sites/all/modules/cck/fieldgroup.module on line 394.
Any help would be really great