Magento – How to add a full-width block above the content

blockslayouttemplatewidgets

How can you add dynamic content above the CMS content?

I am currently trying to implement a full width banner slider above the content. The slider must be different on different pages so I need to be able to pass a variable, preferably through the xml because it needs to differ from each page and I cant use a template file eg: 3colums.phtml because it will use the same slider on multiple different pages.

I have attached an image below of what I want to achieve.

This is the code:

XML

<reference name="content"> 
    <block type="bannerslider/bannerslider" name="bannerslider" template="bannerslider/bannerslider.phtml"> 
        <action method="setCategoryId"><category_id>2</category_id></action> 
    </block> 
</reference>

PHP

echo $this->getLayout()->createBlock('bannerslider/bannerslider')
    ->setCategoryId('1')
    ->setTemplate('bannerslider/bannerslider.phtml')
    ->toHtml()

layout

Best Answer

Use after_body_start or top.container instead of content as a reference.

  • after_body_start is a container placed immediately after the body tag
  • top.container is a container within the header element, below the top menu.

If you use CMS widget instances instead of layout XML, the containers are referenced by "Page Top" and "Page Header".

Related Topic