building tabs

Permalink Browser Info Environment
Hi guys,

I have two fields per item: "name" & "content". The name is displayed as a Tab and the content in this tab. When I load the page with this block the first time, no content is displayed. I need the first tab and content of the first tab to be displayed (first item) then.

I have this code for tabs:
<?php defined('C5_EXECUTE') or die(_("Access Denied.")); ?>
<?php /* This block was made with Designer Content Pro. Visithttp://theblockery.com/dcp for documentation. */ ?>
<script type="text/javascript" src="<?php  echo $this->getThemePath(); ?>/js/kube.tabs.js"></script>
<div class="units-row">
   <nav class="nav-tabs nav-tabs-v unit-30" data-toggle="tabs" data-height="equal" data-active="#1">
       <ul>
         <?php foreach ($controller->getRepeatingItems() as $item): ?>
         <li>
            <a href="#<?php $item->name->display(); ?>">
               <?php $item->name->display(); ?>
            </a>
         </li>
         <?php endforeach; ?>
       </ul>
   </nav>


Is there a possibility to receive the first item name? I need it for activate the first Tab when the page is loaded.

data-active="#Tab_one"


at #Tab_one I need some php code that displays / echoes the name of the first tab.

best regards
Torsten

Edit: I think that don't works with repeating items - after updating the content/names all content is displayed (from all items).

1 Attachment

Type: Discussion
Status: New
tsilbermann
View Replies: View Best Answer
tsilbermann replied on at Permalink Reply
tsilbermann
anyone?
theblockery replied on at Permalink Best Answer Reply
theblockery
Hi Torsten,
I can't know exactly because I'm not familiar with the javascript code you're using, but I can see 2 possibilities based on your code:

1) I don't know if calling $this->getThemePath() works in a block like it does in a theme template. Try View::getInstance()->getThemePath() instead, or just put the javascript in your block's folder (where the view.php file is), in a subfolder called "js" -- concrete5 will load it automatically then.

2) You are using the "name" field for your tab links and id's -- but this will not work because the names have spaces in them. You should instead use a counter number to generate unique id's for each tab, like so:

<?php defined('C5_EXECUTE') or die(_("Access Denied.")); ?>
<?php /* This block was made with Designer Content Pro. Visithttp://theblockery.com/dcp for documentation. */ ?>
<script type="text/javascript" src="<?php  echo $this->getThemePath(); ?>/js/kube.tabs.js"></script>
<div class="units-row">
   <nav class="nav-tabs nav-tabs-v unit-30" data-toggle="tabs" data-height="equal" data-active="#block-<?php echo $bID; ?>-tab-0">
       <ul>
         <?php foreach ($controller->getRepeatingItems() as $index => $item): ?>
         <li>
            <a href="#block-<?php echo $bID; ?>-tab-<?php echo $index; ?>">
               <?php $item->name->display(); ?>
            </a>
         </li>
         <?php endforeach; ?>
       </ul>
   </nav>


Then, the id of the first one to be active will be:
data-active="#block-<?php echo $bID; ?>-tab-0"


Hope this helps!

-Jordan
tsilbermann replied on at Permalink Reply
tsilbermann
Hi Jordan,

thanks a lot. Your solution works fine.

Just to make sure if others need this. In this case it should be (?):
data-active="#block-<?php echo $bID; ?>-tab-0"


Best regards

Torsten
theblockery replied on at Permalink Reply
theblockery
You are correct -- I've fixed my answer to reflect this.
Thanks!

concrete5 Environment Information

Browser User-Agent String

Hide Post Content

This will replace the post content with the message: "Content has been removed by an Administrator"

Hide Content

Request Refund

You have not specified a license for this support ticket. You must have a valid license assigned to a support ticket to request a refund.