Magento – displaying a custom attribute in a static block

Here’s the scenario: I have used Template Master Easy Tabs in my Magento installation, it’s working fine. I’m also using the Red Stage ‘Shipping Price Per Product’ extension so that the products can have their delivery individually priced (it’s handmade hardwood furniture, so it need shipped by a removals firm rather than a courier/ delviery company).

So there’s a custom attribute called ‘shipping_price’ which is added to the default attribute set, and set to be able to be displayed on the front end. Easy tabs is very good, there is a section specifically allowing you to add an specified attribute to one of the tabs. There’s also a different section allowing you to add Static Blocks to your tabs.

My problem though was -> How do you add a custom attribute into one of the Easy Tabs static blocks? It is easy enough but there’s not much on Google about it. There’s tonnes of stuff about displaying static blocks from templates but not much about disaplying templates dealing with custom attributes from static blocks.

So first of all you add your call to your template from your static block. The first mistake is that you might be tempted to use ‘cms/block’ as your block type. That didn’t work for me. I used ‘core/template’;


{{block type="core/template" block_id="product_delivery_price" template="catalog/product/delivery_price.phtml"}}

The next issue is that you can’t just start magically accessing the current product’s attributes from your custom template. You have to pull in the current product from the registry;

So here’s the code;


<?php
    $_helper = $this->helper('catalog/output');
    $_prodID = Mage::registry('current_product')->getId();
    $_product = Mage::getModel('catalog/product')->load($_prodID );

?>

<?php if ($_product->getShipping_price()): ?>
    <div class="delivery-price">£ <?php echo number_format((float)$_product->getShipping_price(), 2, '.', ''); ?></div>
<?php endif; ?>

Note that I’ve hardcoded the ‘£’ sign in (naughty me), we are not doing multi language versions on this store.