How do I add a static or dynamic block in Magento?

Magento provides an easy way to add blocks with using Layout-XML file and also call directly from the phtml file and added to any category page with no programming at all.

Adding Magento Static block:

from XML:

From phtml/php :

From the CMS page content/Shortcode way:

Adding Magento dynamic block:

From XML:

From the CMS page content/shortcode way:

From phtml/php:

or if the block is already existing in the layout you can get it by name:

Note that all functions available to you within the layout XML via are also available to call on any block in our code. For example, if we instantiated a new block to be added / appended to the head, we could execute something similar to this:

Call Magento Block method/function:

There are two syntax to call block method/function as below.


Example :

It shows the category menu.

Adding Magento Content Blocks:
Add Handle in your local.xml/custommodule.xml so it looks like the following

We’re adding a new Block nested within our root. This is a Block that’s distributed with Magento, and will display a customer registration form. By nesting this Block within our root Block, we’ve made it available to be pulled into our simple_page.html Template. Next, we’ll use the Block’s getChildHtml method in our simple_page.phtml file.
Edit simple_page.html so it looks like this

Clear your Magento cache and reload the page and you should see the customer registration form.

6 thoughts on “How do I add a static or dynamic block in Magento?”

Leave a Reply to sharif Cancel reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">