I am unable to add custom tabs to my website and I am looking for a bit of help on how to proceed.
The theme controls the tabs within it's own file /template/catalog/product/view/tabs.php so the normal ways seem not to work with it. Can anyone give me a helping hand?
The important part seems to be
<ul class="meigee-tabs">
<?php foreach ($this->getTabs() as $_index => $_tab): ?>
<?php if($this->getChildHtml($_tab['alias'])): ?>
<li id="product_tabs_<?php echo $_tab['alias'] ?>" class="<?php echo !$_index?' active first':''?>"><a href="#"><?php echo $_tab['title']?></a></li>
<?php endif; ?>
<?php endforeach; ?>
</ul>
<?php foreach ($this->getTabs() as $_index => $_tab): ?>
<?php if($this->getChildHtml($_tab['alias'])): ?>
<div class="meigee-tabs-content" id="product_tabs_<?php echo $_tab['alias'] ?>_contents"><?php echo $this->getChildHtml($_tab['alias']) ?></div>
<?php endif; ?>
<?php endforeach; ?>
<?php foreach ($custom_tabs as $key) {
if(!empty($key)):
?>
<div class="meigee-tabs-content" id="<?php echo $key; ?>_contents"><?php echo $this->getLayout()->createBlock('cms/block')->setBlockId(trim($key))->toHtml() ?></div>
<?php endif; } ?>
If I was to add a tab to this with the tab header "Manufacturer" and the content pulled a CMS block <?php echo $this->getLayout()->createBlock('cms/block')->setBlockId($manu)->toHtml() ?>
My plan is define manufacturer attribute as
<?php $manufacturer = $_product->getAttributeText('manufacturer'); ?>
<?php $manu = strtolower("manufacturer-" . $manufacturer) ;?>
This is so I can then use it to pull an image and static CMS without issues. I just cannot get by the first hurdle…also when I place in <?php $manufacturer = $_product->getAttributeText('manufacturer'); ?>
It gives and error and cuts off the footer.
Best Answer
This is the important part that appear in the given code part.
These are my findings. Template gets all the tabs by requesting
$this->getTabs()
which will return an array that holds information about tabs. My guess is all those tabs are configured through layout XML files. Any ways this method provide an array some what looks like this.So you have two options available
1. Inject your tab through Layout Update
You need to inject your block as other tabs included through layout XML. For this you need to find out which block that holds this template. You can see that tab blocks are included as its child block there. You need to put your custom block in the similar way default tabs are included. This will be the cleanest way to do that. But harder one
2. Forcefully inject your block via template file itself
This will be the easiest way to do this. For this you can use this concept.
First we retrieve tab array and inject my own tab array as element in the parent tab array. Since we put the
alias
with html of cms block(where as all other blocks holds a string for thisalias
), we cannot use default way of rendering the name and content of other blocks. So we separate our custom array entry with anif statement logic
and changed those part according to our need(you can see those changes above).Hope you get an idea how to do that. Let me know the result.