0

I'm trying to load a custom block module tempate file onto the product_view page but it won't render itself.

Here is what I have tried:

I've declared my layout update inside my module config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Company_Module>
            <version>0.1.0</version>
        </Company_Module>
    </modules>
    <global>
        <blocks>
            <module>
                <class>Company_Module_Block</class>
            </module>
        </blocks>
        <helpers>
            <module>
                <class>Company_Module_Helper</class>
            </module>
        </helpers>
        <models>
            <module>
                <class>Company_Module_Model</class>
                <resourceModel>module_mysql4</resourceModel>
            </module>
            <module_mysql4>
                <class>Company_Module_Model_Mysql4</class>
                <entities>
                    <posts>
                        <table>module_posts</table>
                    </posts>
                    <postsmeta>
                        <table>module_postmeta</table>
                    </postsmeta>
                </entities>
            </module_mysql4>
        </models>
        <resources>
            <module_setup>
                <setup>
                    <module>Company_Module</module>
                </setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </module_setup>
            <module_write>
                <connection>
                    <use>core_write</use>
                </connection>
            </module_write>
            <module_read>
                <connection>
                    <use>core_read</use>
                </connection>
            </module_read>
        </resources>
    </global>
    <frontend>
        <layout>
            <updates>
                <module>
                    <file>file.xml</file>
                </module>
            </updates>
        </layout>
    </frontend>
</config> 

Then I have my layout file.xml

<?xml version="1.0"?>
<layout version="1.0">
    <catalog_product_view>
        <reference name="content">
            <reference name="product.info">
                <block type="module/classname" name="custom_name" template="company/module/file.phtml"/>
            </reference>
        </reference>
    </catalog_product_view>
</layout>

My block class

class Company_Module_Block_Classname extends Mage_Core_Block_Template {

    public function getText()
    {
        "Hello World"
    }

}

The my company/module/file.phtml

<?php $this->getText() ?>

When I try to load in my product view page I get an empty value??
<?php echo $this->getChildHtml('custom_name') ?>

Can someone show me what I have missed please??

EDIT

This works in the product view.phtml file but is this the correct way??

<?php   echo $this->getLayout()->createBlock('module/classname')->setTemplate('module/file.phtml')->toHtml();
 ?>
  • please show config.xml code .. your module – Amit Bera Oct 3 '15 at 11:08
  • @AmitBera see update... – user1704524 Oct 3 '15 at 11:26
  • 1
    replace <?php echo $this->getChildChildHtml('custom_name') ?> with <?php echo $this->getChildHtml('custom_name') ?> – Akhilesh Patel Oct 3 '15 at 12:05
1

Removed my module.xml file, removed reference to my module.xml from config.xml and placed below code inside my theme local.xml now I can call

View.phtml

<?php echo $this->getChildHtml('custom_name') ?> 



local.xml 

    <?xml version="1.0"?>
        <layout version="1.0">
            <catalog_product_view>
                <reference name="content">
                    <reference name="product.info">
                        <block type="module/classname" name="custom_name" template="company/module/file.phtml"/>
                    </reference>
                </reference>
            </catalog_product_view>
        </layout>

Place OUTSIDE the Default handler

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.