Magento – A static block on specific pages but on certain page

Picture

We recently needed a solution, to display a small banner with a customer information on all sides but NOT in the checkout. In the cart, however, he should appear.

Contributing to similar topic (But information can only appear on the homepage on any other page LINK) we already had that, but this approach is another.

We want to have a strip on top of the screen, the contents of which comes from a static block. He should be freely edited and without having to access CSS files. The display is similar to the demo store notice of Magento. For this we work with different files.

  1. Create the file
    app / design / frontend /[Eigenes Theme]/[ebenso]/template/page/html/site-info.phtml
  2. app / design / frontend /[Eigenes Theme]/[ebenso]/template/page/html/header.phtml
  3. app/design/frontend/rwd/default/layout/page.xml
  4. app/design/frontend/rwd/default/layout/checkout.xml

The first file we place new and write in the following purely:

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

we open the second file and write

<?php echo $this->getChildHtml('site-info'); ?>

a us anywhere (at which to turn up the block). We have them at the top front

<div class ="header-language-background">

eschrieben. This charges the former data – but only after the next change.

In the third file we are looking for

<block type="page/html_header" name ="header" as="header">

and there add the following line below it

<block type="core/template" name ="site-info" template ="page/html/site-info.phtml" />

Dies sorgt dafür, that the HTML block is loaded. Now this block would be loaded on each side. Since we want, that it is not loaded in the checkout, we have to

adjust the fourth file. Here, then

<checkout_onepage_index translate="label">

searched and this code inserted

<remove name="site-info"/>

We did this by

<remove name="left"/>

made.

In this way we tell the Store, that he should not invite this block in One Page Checkout. Thus, there is no output. The last two changes could be made, incidentally, also in their own local.xml. And, of course, said code can be installed at any other desired location.

Now only the static block is missing. We now create one with the code “site-header-info”. Here you can either write in anything you want. Since we do not change the CSS file, but want to make any changes from the static block, could be a possible HTML code for the block look like this

<div class ="site-info" style="min-height: 50px; background-color: red; color: white; padding-top: 15px; padding-bottom: 15px;">
<p style="text-align: center;">20% save with the coupon code XYZ - all information can be found <span style="text-decoration: underline;"><a style="color: white; text-decoration: underline;" href="http://www.test.de">HERE</a></span>.</p>
</div>

Once you activate the block, the block in the shop displays. to disable it again, the block is completely invisible.

Used in Magento Version 1.9 Comments? Additions? Notes? Gladly!

Published by Covos

Since 2009 I have been working intensively with Magento. I started with the creation and operation of B2C stores. This was extended through my work in the logistics sector. This resulted first specialized B2E systems. Today I work day-a day with exciting B2C, B2B- and B2E projects and reports in this blog about challenges and give insider tips.

Leave a Reply

Your email address will not be published. Required fields are marked *