Magento Code Snippets

Magento is a very large eCommerce package and therefor you easily get lost in the code. We do Magento themes a lot and below you will find a few of our developers most-used code snippets.

Static blocks

Load a static block from the admin in your theme. First add this piece of XML to your cms.xml for example.

<block type="cms/block" name="static_block_name">
	<action method="setBlockId"><block_id>static_block_name</block_id></action>

If you have made the reference in the theme XML you are now able to get the output from the static block in your .phtml file like this.


Price snippets

Format a price integer to a money format including currency symbol.

// Use cart subtotal on cart.phtml

Get the price block including sales etc. on a catalog product page.