get_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 get_block($name, $render = true); ?>
  • $name: this is the name of the block you are looking to return.
  • $render: true or false – this specifies whether to render the block as HTML, or return it as an object.

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
/* Return a block - the top navigation */

$block = get_block("catalog.topnav");
echo $block;
?>

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

Related Functions