Digits
Digits

Reputation: 1351

Use magento CMS block code in template files

This is the first time I am creating a custom tempalte for Magento. I installed a 3rd party plugin, that allows me to use this code in the cms editor:

{{block type='bannerslider/bannerslider' template='bannerslider/bannerslider.phtml'}}

Now, I want to use this on a page in my template. What php code should I use to get this to work ?

I tried

    <?php echo $this->getChildHtml('bannerslider/bannerslider') ?>

But that displays nothing.

Thank you!

Upvotes: 1

Views: 1436

Answers (2)

Digits
Digits

Reputation: 1351

An alternative I received from someone else:

<?php echo $this->getLayout()->createBlock('bannerslider/bannerslider')->setTemplate('bannerslider/bannerslider.phtml')->toHtml();
?>

Upvotes: 0

nevermourn
nevermourn

Reputation: 684

You have to declare your block inside layout file of your custom template (usually, local.xml) under some handle (like default or catalog_product_view).

For example:

<block type="bannerslider/bannerslider" name="banner_home" template="bannerslider/bannerslider.phtml"/>

under <default> handle would let you to call <?php echo $this->getChildHtml('banner_home') ?> in any place of your template. Notice that you have to use name from layout, not block class to call it with getChildHtml.

Upvotes: 2

Related Questions