Make sure the block from the second tab returns something.
You are missing this code at the end of _prepareForm()
method:
$this->setForm($form); //set the form object to the block
return parent::_prepareForm(); //this is not mandatory but it is nice to keep a consistency.
And an other tip, off topic.
Don't declare the names of the fields like this. You might get into trouble.
'name' => 'vendor_h[name]',
You can add this at the top of _prepareForm
after $form = new Varien_Data_Form();
$form->setFieldNameSuffix('vendor_h');
This will transform the names of the fields from field_name
to vendor_h[field_name]
.
In a similar way you can add a prefix for the ids of the field with this line
$form->setHtmlIdPrefix('some_prefix_');
This will transform the id of the fields from field_id
to some_prefix_field_id
.
This is the important part that appear in the given code part.
<?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; ?>
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.
array(
'index1' => array(
'alias' => 'alias_1',
'name' => 'name_1', //not sure
'title' => 'title_1'
.....
),
'index2' => array(
'alias' => 'alias_2',
'name' => 'name_2', //not sure
'title' => 'title_2'
.....
),
.....
)
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.
<?php
//get tab array
$tabs = $this->getTabs();
//create an array for your tab
$my_tab = array(
'my_tab' => array(
'alias' => $this->getLayout()->createBlock('cms/block')->setBlockId($manu)->toHtml(),
'title' => 'Manufacturer'
));
//inject your block to tab array
array_merge($tabs, $my_tab);
?>
<!-- need some modification here -->
<ul class="meigee-tabs">
<?php foreach ($tabs as $_index => $_tab): ?>
<?php if($_index != 'my_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 else : ?>
<li id="product_tabs_manufacturer" class="<?php echo !$_index?' active first':''?>"><a href="#"><?php echo $_tab['title']?></a></li>
<?php endif; ?>
<?php endforeach; ?>
</ul>
<?php foreach ($tabs as $_index => $_tab): ?>
<?php if($_index != 'my_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 else : ?>
<div class="meigee-tabs-content" id="product_tabs_manufacturer_contents"><?php echo $_tab['alias'] ?></div>
<?php endif; ?>
<?php endforeach; ?>
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 this alias
), we cannot use default way of rendering the name and content of other blocks. So we separate our custom array entry with an if 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.
Best Answer
On your tab you can make the function
canShowTab
. This will return a boolean value if the tab can be shown or not. In this function you can perform a check to see if your conditions are matched. A good example of this is the blockMage_Adminhtml_Block_Customer_Edit_Tab_View
which only shows after the customer has been saved.