AMD does not work in the foot

I've no previous experience with AMD, so I try it now with the basic example from the DOCs.

// in views/default/myplugin/say_hello.js
define(function(require) {
var elgg = require("elgg");
var $ = require("jquery");

It works well on a page. However, I want to add some JS to the footer of all the pages. So, I extended the foot.php and the above code does not work there.

When I add some JS script and other stuff directly to the foot it is OK, but not with the AMD.

What is my mistake? How to add AMD correctly to the foot?

Thank you.

  • I forgot to add - I load this module on the page and on the foot.php with:



  • can you see the AMD file being loaded as an external resource?

  • Adding elgg_require_js("myplugin/say_hello"); in start.php with the mentioned code will be display at the footer always:


    So you don't need to extend foot.php for it.

  • Jerom - I cannot see the AMD file being loaded as an external resource - it is really strange. The elgg_require_js("myplugin/say_hello"); is in the foot with other stuff. The other stuff is on the page but not AMD. I wish I understand why.

    RvR - yes it amazingly appears in the footer of all the pages - here again I do not understand why it is in the footer, while the script is in the start.php.

    Thank you both very much . It is an important lesson for me.


    The DOCs of Elgg is a great resource for developers. However, a beginner and amateur like me needs a comprehensive overview of the whole Elgg framework. A tutorial book or a course which explains gradually the concept and the components. Do you know about such option?

    Thank you very much for your kind help.

  • I do not understand why it is in the footer, while the script is in the start.php

    In my reply I've added link to code where all AMD dependencies calls. You can add your module on any page/view of your site not start.php only.