Tag Archives: add statick block in phtml

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.