Download & Extend

Correct code to include tabs in tpl.php

Project:CCK Fieldgroup Tabs
Version:6.x-1.2
Component:Code
Category:support request
Priority:normal
Assigned:Unassigned
Status:active

Issue Summary

Hi - first, love the module - exactly what I needed, thanks! :)

The one problem I'm having though is that I decided to create a separate template for the content type that uses the tabs. The name of this file is nod-plans-tpl.php. When I didn't find the print command easily to print the tabs I ended up hardcoding the unordered list menu inside this file. So now my code for the plans reads:

<div class="drupal-tabs">
<ul id="planspg">
<li><a href="#tabset-1">Floor Plans</a></li><li><li><a href="#tabset-2">Model A</a></li><li><a href="#tabset-3">Model B</a></li><li><a href="#tabset-4">Model C</a></li><li><a href="#tabset-5">Model D</a></li></ul>

Though the page works perfectly and I like that I was able to give the list their own id for customizing the look I now notice that I lost the ability to disable tabs if their is no content in that section. If you look at the list items in the code above you'll notice that I have tabs for Models A through D. The content in these sections only contain one image.

I guess my question is what is the correct code to include the tabs in a tpl.php page so that the tabs without content disappear? Or is there an if statement that I can include in the li tag that would give a class of "tabs-disabled" if the image for the each model doesn't exist?

So far I've tried the following code but unfortunately it either gives me a parse error, disables the tab even when the corresponding content DOES exist or it does nothing.

<li class="<?php if (content_format('field_model_a_img', $field_model_a_img[0]) == '0') { echo "tabs-disabled"; }else{ echo "none"; } ?>"><a href="#tabset-2">Model A</a></li>

Any help on this is appreciated! Thanks!

Comments

#1

Yes, I second this request. Would love to be able to use a node.tpl.php to customise bio and use cck fieldgroup tabs too.

#2

Any news on this?

#3

+1

#4

+1 subscribing
Unfortunately, without being able to output tabs in custom node template, I can't use them.

#5

+1

And I think you can check whether the element in the group is empty();

#6

+1

I'm looking for the same code -- it should really be documented somewhere, it's a pretty essential part of making tabs work on custom node templates.

#7

Version:5.x-1.x-dev» 6.x-1.2

I have same question / requirement. I need to make custom layout for a node type for which I am using CCK Field Group tabs. I tried using contemplate, node-type.tpl.php and even panels 3. For any of these options unable for find out what code or option to use to render CCK Fieldgroup tabs. Any help or pointer to a solution will be highly appreciated.

Prasad

#8

+1, subscribing

I'd like to render a specific type of node's comment form on a tab, so I'm looking for a way to put this - <?php print comment_render($node, NULL); ?> - in a tab I create on the tpl.php. I think. But yep, having a little more control over these would be super awesome.

#9

This is the code I use but for some reason I can't seem to make the empty tabs go away. Any suggestions?

<div id="tabs-tabset" class="drupal-tabs tabs">
     <ul class="clear-block ui-tabs-nav tabs tabs primary">
     <li><a href="#tabs-1-1">Tab 1</a></li>
         <li><a href="#tabs-1-2">Tab 2</a></li>
              <li><a  href="#tabs-1-3">Tab 3</a></li>
           </ul>
<div id="tabs-1-1" class="fragment">
            <?php foreach ((array)$node->field_name as $item) { ?>
            <div class="field-item">
            <?php print $item['value'] ?></div>
            <?php } ?>
   </div>
  <div id="tabs-1-2" class="fragment">
              <?php foreach ((array)$node->field_name as $item) { ?>
            <div class="field-item"><?php print $item['value'] ?></div>
            <?php } ?>
    </div>
    <div id="tabs-1-3" class="fragment">
              <?php foreach ((array)$node->field_name as $item) { ?>
            <div class="field-item"><?php print $item['value'] ?></div>
            <?php } ?>
      </div>
</div>

#10

I figured a solution. Add if statement between list elements. Like so:

<?php if(!empty($node->field_name[0]['value'])): ?>
     <?php echo '<li><a id="someBtn" href="#tabs-1-1">Tab 1</a></li>'; ?>
     <?php endif; ?>

#11

How about this?

<?php print theme_tabset($node->content['fieldgroup_tabs']); ?>

Then you just implement theme_tabset() and theme_tabpage() to further customize the output.

#12

That worked very well, thanks miphol!

I must say I was having hard time theming the output of that call. What will be the best way to override the output?
I can't find the theme_tabset() function...

nobody click here