MAGENTO, PHP

Add custom html in magento without changing existing code

Add custom html in magento without changing existing code

Sometimes when you are developing an extension you need to inject your custom banners & html snippet to highlight your information properly. In that case this method works perfectly. In this tutorial I am going to show how to add custom html in magento without changing existing code.

Add custom html in magento without changing existing code
Add custom html in magento without changing existing code

Frontend name in etc folder

app/code/local/Javascript/Solution/etc/config.xml

Write frontend name of the controllers in config.xml file in your module

Create a block file

Create a block file and extends Mage_Core_Block_Template in your custom module

I am here going to add a small html part just after order review section at onepage checkout steps. The html shows a banner of offer of my payment gateway.

Create Layout xml (Important)

Before writing your own xml, we will copy paste the xml part from its core layout block, that is already written. Order review block xml is –

app/design/frontend/base/default/layout/checkout.xml (core xml of onepage checkout)

 

Above code is core part,  now lets override this xml. Create a file

app/design/frontend/base/default/layout/javascriptsolution.xml

As you can see I have removed a lot of part from the xml and simply written a block section of my own phtml. Please make sure to keep only reference tag & your custom block rest remove all as it overrides the existing phtml.   <reference>   is responsible to inject html before or after an existing block. If you remove the reference tag it will override the existing block. Now in block tag make sure to add “before” & “type” attribute properly.

Create the phtml file

app/design/frontend/base/default/templates/javascriptsolution/review.phtml

 

Add custom html in magento without changing existing code
Add custom html in magento without changing existing code

Conclusion

Its so great to achieve this tricky part of magento where you have a liberty of customising html without hampering existing code. Thanks happy coding ~ Kishor

Fore more on magento 2 follow these links Create custom magento 2 themeCreate custom Magento 2 module

Share

Leave a Comment

Your email address will not be published. Required fields are marked *