I need to build custom extension (code pool 'community') that should add some Javascript just before the HTML body tag is closed.

So far after some research it seems that the most elegant way to do this is to use 'before_body_end' reference. I found this article and recreated all steps exactly as described (except I'm using the 'community' code pool) on a fresh clean default Magento CE installation. But nothing happens. The extension is enabled in 'Configuration/Advanced', cache is cleaned, no errors at all... The custom phtml isn't loaded.

Can anyone describe (or refer to) what steps should be done to make it work?

Maybe there is another way (not with 'before_body_end') to make it work?

1 Answer 1


This requirement can be easily achieve by a backend setting.

Magento have provide an input field to system configure where you can put any html/script code and that will be inject code before </body>.

Just goto Admin>System>Configuration>Design>Footer

Put your html and script code at field Miscellaneous HTML.

enter image description here

If want do this by codexpedia. extension then there are some location modification required on your layout xml and template phtml

Put addblock.xml from app/design/frontend/default/default/layout/ to app/design/frontend/base/default/layout/

Put myblock.phtml from app/design/frontend/default/default/templat/addblock/ to app/design/frontend/base/default/templat/addblock/

As i move this two file to base package,that it should be call frontend thmes

  • Appreciate this, thanks. The 1st solution isn't automated. The 2nd - I already tried to move these files to 'base/default', but without success. Anyway, the steps described in "www.smashingmagazine.com/2012/11/introducing-magento-layout/" actually work (but this answer can't be answered due to don't-post-only-link-answer rule.
    – a1111exe
    Oct 18, 2015 at 0:33
  • A couple things...first using the database to store page JavaScript only results in untracked code and a loss of accountability. Second, the 'base' design package is owned by the Magento core and should not be internally modified. From my experience the safest and cleanest way to accomplish this task is to make a JS file containing the desired functionality and using the local.xml file to add it to the appropriate block. Overriding the page/html/footer.phtml file locally is also totally acceptable. Oct 18, 2015 at 0:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.