Magento Imagine Awards 2019 Finalist

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”]

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() ?>

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…

Search engine optimisation (SEO) is an important factor for any website and should not be ignored. If you don’t know,…

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…

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.

To find out more about how we use your data, read our Privacy Policy