I tried this code outside the extension, like view.phtml on the theme folder, and its working fine, however I need it to put this inside the extension for following the rules in editing magento. I think I have missing something, or I need to extend some class. Any thoughts regarding this?
P.S I am just started learning to create a module in Magento. This is very much appreciated for your help.