1

I need to add different sliders on each product detail page. I am using slider plugin to achieve this. But the block code

{{block type="bannerslider/default" name="bannerslider.bannerslider" template="bannerslider/bannerslider.phtml" bannerslider_id="your_bannerslider_id"}} 

is not working for product detail page.

It shows the same code as output if I use it in short description field of product detail page and works fine for normal CMS page.

Please suggest...

1
$this->getLayout()->createBlock('bannerslider/default')->setTemplate('bannerslider/bannerslider.phtml')->setBannersliderId('yourabannerid')->toHtml();

Need to put this code in view.phtml...

1

The code snippet that you have tried is a Magento widget. From your question its clear that, this widget is providing by an external extension. A magento widget is just like any other widget that are using in other frameworks. It does a specific task with a short code, so that non-technical users can also use that code. However you cannot use that widget code everywhere in the case of Magento. For example, you can use widget in CMS Pages, but not in a template file. If you put this code inside template, Magento treats it like normal text.

So in order to get output, instead of using widget, you need to include corresponding block in appropriate place. Here you are trying to add this block in product detail page. That means, you need to add the block correspond to the widget in catalog_product_view handler in layout file.

For example, you can use this code

File : app/design/frontend/<package>/<theme>/layout/local.xml

<layout>
    <catalog_product_view>
         <reference name="product.info">
             <block type="bannerslider/default" name="product.slider" as="product_slider" template="bannerslider/bannerslider.phtml">
                 <action method="setBannersliderId"><slider_id>your_bannerslider_id</slider_id></action>
             </block>
         </reference>
    </catalog_product_view>
</layout>

Now you need to call this block in product detail template. ie

File : app/design/frontend/<package>/<theme>/template/catalog/product/view.phtml

<div><?php echo $this->getChildHtml('product_slider'); ?></div>

You can put this code snippet wherever it needs to show inside view.phtml.

Note: My friend @AmitBera gave you a short form of what we have done here. You can also use that code in view.phtml

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.