We're a finalist for the eCommerce awards 2017.

Calling static blocks from anywhere in Magento

Magento eCommerce gives us the power to add our own snippets of html wherever we wish. Magento calls these snippets ‘static blocks’. To create a new block go to CMS > Static Blocks at the top right of this list click ‘Add New Block’.

Enter your title and unique identifier e.g. ‘top-advert’. Set the block to enabled and enter the content of the block into the WYSIWYG editor. This is all you need to do Magento side. To call the block onto the frontend of the website open up your template file. For example if I want to call my advert into my product listing I would open:

[pyg language=”bash”]
/app/design/frontend/theme/default/template/catalog/product/list.phtml
[/pyg]

I want my advert to appear above the product list so I find the opening html for the products list and put this before it:

[pyg language=”php”]
getLayout()->createBlock(‘cms/block’)->setBlockId(‘top-advert’)->toHtml() ?>
[/pyg]

Thats it, everything you need to know ūüôā


Subscribe via email

Sign up to get notifications of new posts by email.

Share this article

Posted in Magento

Other posts you might like

Last Saturday 12th November myself and eight of my teammates donned our iWeb hoodies, packed our rain macs and headed…

As web developers we like to make use of the best open source platforms¬†available¬†in the development of our¬†brochure¬†and eCommerce websites.¬†We…

Since our company was founded in 1995, we have been building fully bespoke eCommerce websites for our clients. We now…

Call us on 01785 279920

Our friendly Magento experts are happy to answer your questions.

Follow us!

Get the latest eCommerce news, reviews and expert advice in your inbox.