0

Been looking at this online but didn't seem to find an answer that relates to my problem.

I have a static block on top of my page. Very simple one

   <div class="col-sm-12" style="background-color: red;>
<div class="row">

<h2 style="text-align: center; height:70%;"> I'm out of the office</h2>

</div>
</div>

I setup it up on my header.phtml like this

  <?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('header_out')->toHtml(); ?>

The thing is I don't want it on my cart and checkout pages.

I thought about css and display:none, but since that's added on the header, how can I hide them on those two pages?

Thanks

1 Answers1

0

Best Practice Answer:

You can set the block like this on your xml files (eg. local.xml)

 <default>
    <reference name="header>
            <block type="cms/block" name="header.out">
                <action method="setBlockId"><block_id>header_out</block_id></action>
            </block>
    </reference>
 </default>

Then replace this:

<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('header_out')->toHtml(); ?>

With this

echo  $this->getChildHtml('header.out');

This will render your block.

To remove it from a certain page you can do it like so.

For example you said the cart page. As you can see everypage on magento on its body class tag has an identifier for lets say you wanted to remove the block from the cart which has this tag

<body class="checkout-cart-index">

You can do it like so in your xml file.

<checkout_cart_index>
    <remove name="header.out" />
</checkout_cart_index>

(Notice the dashes need to be underscores in the xml.

Quick Way | Not ideal

With css.

.checkout-cart-index (class you are targeting),
.checkout-onepage-index (class you are targeting) {
  display:none;
}