In the image below you can see the structure of my module:
enter image description here
This is the content of Block/Product/View.php:
<?php
class NetGroup_Attributegrouping_Block_Product_View extends Mage_Core_Block_Template
{
function _construct(){
$this->setTemplate('netgroup/attributegrouping/list.phtml');
}
function indexAction(){
$this->setTemplate('netgroup/attributegrouping/list.phtml');
}
}
This is the content of etc/config.xml:
<?xml version="1.0"?>
<config>
<modules>
<Netgroup_Attributegrouping>
<version>1.0.0</version>
</Netgroup_Attributegrouping>
</modules>
<global>
<blocks>
<netgroup_attributegrouping>
<class>Netgroup_Attributegrouping_Block</class>
</netgroup_attributegrouping>
</blocks>
<helpers>
<netgroup_attributegrouping>
<class>Netgroup_Attributegrouping_Helper</class>
</netgroup_attributegrouping>
</helpers>
</global>
<admin>
<routers>
<adminhtml>
<args>
<modules>
<netgroup_attributegrouping after="Mage_Adminhtml">Netgroup_Attributegrouping_Adminhtml</netgroup_attributegrouping>
</modules>
</args>
</adminhtml>
</routers>
</admin>
<adminhtml>
<layout>
<updates>
<netgroup_attributegrouping>
<file>netgroup_attributegrouping.xml</file>
</netgroup_attributegrouping>
</updates>
</layout>
</adminhtml>
<frontend>
<layout>
<updates>
<netgroup_attributegrouping>
<file>netgroup_attributegrouping.xml</file>
</netgroup_attributegrouping>
</updates>
</layout>
</frontend>
</config>
In the design/frontend/netlogiq/default/layout/netgroup_attributegroping.xml content is:
<?xml version="1.0"?>
<layout>
<catalog_product_view>
<reference name="product.info">
<block type="netgroup_attributegrouping/product_view" ></block>
</reference>
</catalog_product_view>
</layout>
In the design/frontend/netlogiq/default/template/netgroup/attributegrouping/list.phtml content is:
<?php
echo 111111111111;
?>
AND finally in the app/design/frontend/netlgiq/default/template/catalog/product/view.phtml i have :
<div class="TEST"> TEST<br>
<?php echo $this->getChildHtml('netgroup_attributegrouping'); ?>
</div>
I want to display my product in catalog/product/view.phtml. It does not display "1111111111" . I know there is a lot of mistakes, but what should i do , to make my module to work ? thx
2 Answers 2
<reference name="product.info">
<block type="netgroup_attributegrouping/product_view" name="netgroup_attributegrouping" as="netgroup_attributegrouping"></block>
</reference>
then this will work `<?php echo $this->getChildHtml('netgroup_attributegrouping'); ?>`
-
ok it works, but could you explain me this part : name="netgroup_attributegrouping" as="netgroup_attributegrouping" ?Attila Naghi– Attila Naghi2014年07月30日 08:13:06 +00:00Commented Jul 30, 2014 at 8:13
-
1you are calling the getChildHtml and passing the parameter which is the name of the block ie netgroup_attributegrouping. but their is no block with this name netgroup_attributegrouping.so when you calling block with this name you are not getting this block.so we have to give a name to this blockPradeep Sanku– Pradeep Sanku2014年07月30日 08:20:13 +00:00Commented Jul 30, 2014 at 8:20
-
any ideea why $_product is null if a put this code: $_product = $this->getProduct(); int list.phtml ?Attila Naghi– Attila Naghi2014年07月30日 09:36:11 +00:00Commented Jul 30, 2014 at 9:36
You have not mention the block name and as. So change your layout file need to like this
<?xml version="1.0"?>
<layout>
<catalog_product_view>
<reference name="product.info">
<block type="netgroup_attributegrouping/product_view" name="netgroup_attributegrouping" as="netgroup_attributegrouping"/>
</reference>
</catalog_product_view>
</layout>
Then only you can get the file by this code
<?php echo $this->getChildHtml('netgroup_attributegrouping'); ?>
Note: You have to pass block as value not block name to the getChilHtml function parameter
-
it works, thx. question: what is name="product.info" ? where is defined? and im confused a little bit. I saw using this characters "/", "_","." in the name and i do not know the differences between themAttila Naghi– Attila Naghi2014年07月30日 08:16:28 +00:00Commented Jul 30, 2014 at 8:16
-
@Chester check your
catalog.xmlfileproduct.infois block name , so you have call that use that block.MeenakshiSundaram R– MeenakshiSundaram R2014年07月30日 08:17:29 +00:00Commented Jul 30, 2014 at 8:17 -
@Chester "/", "_","." i can't understand what your askingMeenakshiSundaram R– MeenakshiSundaram R2014年07月30日 08:19:12 +00:00Commented Jul 30, 2014 at 8:19
-
what does "." represents in the name ?Attila Naghi– Attila Naghi2014年07月30日 08:20:05 +00:00Commented Jul 30, 2014 at 8:20
-
@Chester it just a character, you can use any thing in this. i.e., Each block name must be unique.MeenakshiSundaram R– MeenakshiSundaram R2014年07月30日 08:21:42 +00:00Commented Jul 30, 2014 at 8:21