0

In my magento store I have the recently viewed products block and newsletter signup block inside my footer as shown with the below code all working ok:

footer.phtml

<?php echo $this->getLayout()->createBlock('reports/product_viewed')->setTemplate('reports/product_viewed.phtml')->toHtml(); ?>

<?php echo $this->getChildHtml('footer.newsletter') ?>

On one of my CMS pages i want to hide these 2 blocks. In the design admin tab for my CMS page i have already hidden the breadcrumbs with the below in the Custom Layout Update XML section, again working fine:

<reference name="root">
    <remove name="breadcrumbs" />
</reference>

I cannot seem to come up with the correct code to remove these blocks. I have tried several lines of code for each block:

<reference name="footer">
    <remove name="reports.product.viewed" />
</reference>

<reference name="root">
    <remove name="footer.reports.product.viewed" />
</reference>

<reference name="footer">
    <action method="unsetChild"><alias>reports.product.viewed</alias></action>
</reference>
1

I would love to share my thoughts on your code. So this is the code that you have tried in your footer.phtml

<?php echo $this->getLayout()->createBlock('reports/product_viewed')->setTemplate('reports/product_viewed.phtml')->toHtml(); ?>

<?php echo $this->getChildHtml('footer.newsletter') ?>

Your first code cretes a new block and render its content. Code is correct and you got output. However your block is not set with a name. Hence you cannot refer your block in layout update files. In layout update XML files every block is referencing by its name. So the first step is to set a name for your block.

Footer section is normally cached. So some times even if we unset some blocks from that part, it won't see get affected in frontend. Avoiding this issue is somewhat a long step. However in getChildHtml() method, you can specify whether the block need to use cache to render it. For this you need to pass false value as its second parameter. So in effect the code inside footer.phtml should look like this.

<?php echo $this->getLayout()->createBlock('reports/product_viewed', 'footer_product_viewed')->setTemplate('reports/product_viewed.phtml')->toHtml(); ?>

<?php echo $this->getChildHtml('footer.newsletter', false) ?>

See I have specifed name for reports/prodcut_viewed block by passing a second parameter in createBlock() and also specified false as second parameter in getChildHtml() method.

Now your layout XML file should look like this.

<cms_page>
    <reference name="footer">
        <remove name="footer_product_viewed" />
        <remove name="name_of_footer_news_letter_block" />
    </reference>
</cms_page>

This will remove these two blocks from every cms pages. Hope that gives you some idea

  • Thank you very much for the detailed post, appreciate it as i'm just starting off with magento so learning as i go. That all makes sense and the newsletter is now gone but the recently viewed still shows. I've tried placing the xml code above in both the layout.xml and the in the Custom Layout Update XML in the cms page itself – odd_duck Sep 3 '14 at 8:29
  • Ah ... I am a fool.. That is because we are put that block inside a template. Layout files will processed before template files get processed. So in order to make it work, you need to include that block through layout file itself. – Rajeev K Tomy Sep 3 '14 at 8:33
  • All sorted by doing both these methods, thank you! – odd_duck Sep 3 '14 at 8:56
  • happy to help you – Rajeev K Tomy Sep 3 '14 at 10:13
0

you can do doing current module and controller check and hide according to it try this

    <?php
        $getControllerName=Mage::app()->getRequest()->getControllerName();
        $getRouteName=Mage::app()->getRequest()->getRouteName();
        $getModuleName=Mage::app()->getRequest()->getModuleName();


        if(Mage::getSingleton('cms/page')->getIdentifier()=='youmatc_cmspage__identifier'&& ($getControllerName=='page') &&($getModuleName=='cms')){
// donot show two block for you match cms page
        }elseif( ($getControllerName=='page') &&($getModuleName=='cms')){
//show on other cms page
       echo $this->getLayout()->createBlock('reports/product_viewed')->setTemplate('reports/product_viewed.phtml')->toHtml();
         echo $this->getChildHtml('footer.newsletter') ;
        }else {
// show rswt of pagesa all pages
        echo $this->getLayout()->createBlock('reports/product_viewed')->setTemplate('reports/product_viewed.phtml')->toHtml(); 
        echo $this->getChildHtml('footer.newsletter') ;
        }

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.