0

I'm using custom block to show my module logo over each product, now since catalog_product_view tag it shows the logo at product details page only, the problem is that I want to show the icon on each page on each product, whether it is home page, product list, detail, etc. how to achieve this using blocks

Here is the code

Module Configuration (app\etc\modules\NS_Mymodule.xml)

<config>
    <modules>
        <NS_Mymodule>
            <active>true</active>
            <codePool>community</codePool>
        </NS_Mymodule>
    </modules>
</config>

Configuration XML (app\code\community\NS\Mymodule\etc\config.xml)

<config>
    <modules>
        <NS_Mymodule>
            <version>1.0.1</version> 
        </NS_Mymodule>
    </modules>
    <global>
        <helpers>
            <Mymodule>
                <class>NS_Mymodule_Helper</class>
            </Mymodule>
        </helpers>
        <blocks>
            <mymodule>
                <class>NS_Mymodule_Block</class>
            </mymodule>
        </blocks>
    </global>
    <frontend>
        <layout>
            <updates>
                <mymodule>
                    <file>mymodule.xml</file>
                </mymodule>
            </updates>
        </layout>
    </frontend>
</config>

Block Class ( app\code\community\NS\Mymodule\Block\Showicon.php )

class Ns_Mymodule_Block_Showicon extends Mage_Core_Block_Template
{
    public function myfunction()
    {
        return "Hello tuts+ world";
    }
}

Layout XML ( app\design\frontend\rwd\default\layout\mymodule.xml)

<layout version="1.0.1">
    <catalog_product_view>
        <reference name="product.info">
            <block type="mymodule/showicon" as="ns_media" name="mymodule_showicon" template="mymodule/showicon.phtml" />
        </reference>
    </catalog_product_view>
</layout>

Template File (app\design\frontend\rwd\default\template\mymodule\showicon.phtml)

<h1>SHOW ICON HERE</h1>

and in the app\design\frontend\rwd\default\template\catalog\product\view.phtml

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

right after

<?php echo $this->getChildHtml('media') ?>
  • Use <default> layout handle to have your template and block on all the pages. – Anshu Mishra Sep 21 '15 at 15:34
  • you mean rather of <catalog_product_view> we use <default> – riksof-zeeshan Sep 22 '15 at 5:49
1

Use CSS instead of HTML - solves all your problems and the used class everywhere should be product-image

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.