I currently have my Drupal Primary Links set up to act as tabs. I used the Basic instructions for adding graphic tabs to your Drupal theme doc to set it up -- and it works pretty well.

When I click on a Primary Link (which is a tab) - it goes to the appropriate page and the tab appears selected. So if the primary link path is "products" being on "website.com/products" the tab is selected. However, if the path is "products/somepage.html", the tab is no longer selected. However, I want to the tab to be selected.

The behaviour makes sense when viewed in the context of how links are labeled as "active" (which is the mechanism upon which the tab selection is contingent on). Below is the code used within my .tpl.php file:

<?php if (count($primary_links)) : ?> 
<ul id="primary">
<?php foreach ($primary_links as $link): ?> 
<?php $class = ""; ?> 
<?php if ( stristr($link, 'active') ) : ?> 
<?php $class = 'id="current"'; ?> 
<?php endif; ?> 
<li <?php print $class ?>><?php print $link?></li> 
<?php endforeach; ?> 
</ul>
<?php endif; ?>

In attempting to tackle this problem, I'm inclined to parse the path of the url and determine what "directory" the end-user is browsing, and setting the tab to be active. Is there a more elegant solution to this -- one that doesn't require the hard-coding of values to be used in the conditional statements?

Thanks for your help.

Comments

monkeybeach’s picture

This has to be pretty common in sites that use tabs for their top level menu's (amazon.com for instance). Is there an easier solution via the CMS?