1

In my header.phtml I've got the following code

<?php 
    echo  $this->getLayout()->createBlock('nwdrevslider/revslider')->setAlias('slidername')->setBlockId('sliderid')->toHtml(); 
?>

So I want to remove it from the product view page so to do so in my catalog.xml I've write the following code

<catalog_product_view translate="label">

    <reference name="header">

       <remove name="slidername" />

        <!-- even tried following but didn't work -->

        <remove name="sliderid" />

        <!-- even tried following but didn't work -->

        <action method="unsetChild"><name>slidername</name></action>

        <!-- even tried following but didn't work -->

        <action method="unsetChild"><name>sliderid</name></action>

    </reference>

</catalog_product_view>

Using Magento 1.7.0.2.

Let me know if you want more information.

Revolution slide is been used

3
  • Only catalog page ? Share Your url
    – Magento 2
    Sep 20, 2016 at 10:10
  • @Kothari : It's in my local can't share, Yes only from product view page I want it to be removed. Sep 20, 2016 at 10:11
  • You using create block in phtml so not remove it from xml layout. for this need use current product registry code Mage::registry('current_product'); $product_id = Mage::registry('current_product')->getId(); // check product id $product_id not exist then show it. Sep 20, 2016 at 10:14

2 Answers 2

3

you are calling the block directly so xml will not work. call it like this

if(!Mage::registry('current_product')) {

    echo  $this->getLayout()->createBlock('nwdrevslider/revslider')->setAlias('slidername')->setBlockId('sliderid')->toHtml(); 

}
0
3

Here's the best practice.

First, instead of generating the block directly in your header.phtml you should use your local.xml to assign the block to your template:

<default>
    <reference name="header>
            <block type="cms/block" name="slidername">
                <action method="setBlockId"><block_id>sliderid</block_id></action>
            </block>
    </reference>
</default>

Then in your header.phtml you can replace:

echo  $this->getLayout()->createBlock('nwdrevslider/revslider')->setAlias('slidername')->setBlockId('sliderid')->toHtml(); 

With:

echo  $this->getChildHtml('slidername'); 

Once you're done with this you can add the following to your local.xml :

<catalog_product_view>
    <remove name="slidername" />
</catalog_product_view>
1
  • Yes even I prefer this way but It's hard coded by some other developers in base file and I can't change it for a while...Thanks @RaphaelatDigitalPianism Sep 20, 2016 at 10:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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