Output Product Attribute in Magento

6 May 2015| Post by Graham1 minutes


You can output product attributes in Magento using the following code :

getResource()->getAttribute(‘my_attribute’)) : ?>

I have seen a lot of tutorials using code similar to the below :


This is bad practice in my opinion because if the attribute was to ever get deleted from the Magento interface by mistake then it could cause a “Call to getFrontend on a non object” PHP error, potentially breaking the page and hindering the users experience of the website. It is always good to write defensive code that will handle unexpected errors.