1

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

  • have u tried at header phtml file – Amit Bera Nov 26 '15 at 8:36
  • Thanks for the reply .I have tried to use widgets which seemed like the best bet after doing some research but the widgets dont show up on any of my pages?????. – Brad Duncan Nov 26 '15 at 9:15
1

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".

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.