the_block()

« Go back to Template Functions

Description

Returns a custom block, previously created within the XML files of your particular Magento theme.

This block could be the default topnav, sidebar cart, custom cart, category listing, bespoke navigation; literally any block created through Magento using the standard XML method.

Parameters

<?php the_block($name); ?>
  • $name: this is the name of the block you are looking to display.

Usage

When making a block in Magento, you will most likely create a PHTML file, and reference that file in one of the many XML files. The XML reference will look similar to to this:

<block type="catalog/navigation" name="catalog.topnav" template="catalog/navigation/top.phtml"/>

Take note of the following: name=”catalog.topnav”.

<?php
/* Display a block - the top navigation */

the_block("catalog.topnav");
?>

You can use the above method to display any block from Magento.

Related Functions