Hi
I have a plugin that used to just extend the js/elgg.php view with the js it needed to load in. The problem is that I can't simply says elgg_register_js() since there is some php in the js, some variables and stuff that are loaded into the script. So how can I get the php-js lazy-loaded when I need it? ( and no I don't like just extending the view, because then it will load at all pages and that's both bad practice causing me problems, and inefficient).
Thank you!
info@elgg.org
Security issues should be reported to security@elgg.org!
©2014 the Elgg Foundation
Elgg is a registered trademark of Thematic Networks.
Cover image by RaĆ¼l Utrera is used under Creative Commons license.
Icons by Flaticon and FontAwesome.
- Brett@brett.profitt

Brett - 0 likes
- elgg_register_js() can point to the url of a JS view (more on that in a second). The JS view can use PHP.
- There is no client side lazy loading JS system in place. elgg_register_js() will register JS to be loaded on pages drawn when elgg_load_js() is called.
- Static views (like the CSS and the JS you extend) will be cached on the server and client side. Yes, it's good to keep JS slim, but unless you have KBs of JS, it shouldn't be a huge problem.
With that out of the way, here's an example of how to register a JS simplecache URL to be loaded. This is from the the Wire plugin: In init (https://github.com/Elgg/Elgg/blob/master/mod/thewire/start.php#L27): // register the wire's JavaScript $thewire_js = elgg_get_simplecache_url('js', 'thewire'); elgg_register_js('elgg.thewire', $thewire_js, 'footer'); In the pages or view in which you want the JS loaded (https://github.com/Elgg/Elgg/blob/master/mod/thewire/views/default/forms/thewire/add.php): elgg_load_js('elgg.thewire'); The call to elgg_get_simplecache_url() is what allows the JS view to be cacheable. That functions looks for views at <viewtype>/js/<name>, so the view file for the wire is at mod/thewire/views/default/js/thewire.php
You must log in to post replies.A few misconceptions: