Invision Community 4: SEO, prepare for v5 and dormant account notifications Matt November 11, 2024Nov 11
Posted April 3Apr 3 Hello everyone!I'm making an application for IPS5. How can I add my custom JS file to all frontend pages in IPS5? In IPS4 I hooked up to the Output class and rewrote the getTitle() method. However, this method not working in v5. And I did not find any Event calling during content output.Please, help.
April 3Apr 3 Community Expert Typically JS files are loaded by hooking into the Dispatcher class (for v4).In v5, we created the Loader extension to handle this kind of situation. The Loader has several methods that allow you to inject JS, CSS, or even manipulate output immediately before execution is complete.
April 3Apr 3 Author Typically JS files are loaded by hooking into the Dispatcher class (for v4).In v5, we created the Loader extension to handle this kind of situation. The Loader has several methods that allow you to inject JS, CSS, or even manipulate output immediately before execution is complete.Thank you Esther E!Can you explain a little bit more about Loader extension implementation?
April 3Apr 3 Community Expert How can I add my custom JS file to all frontend pages in IPS5?Example: public function onFinish() : void { if( count( Lang::languages() ) == 1 ) { Output::i()->cssFiles = array_merge( Output::i()->cssFiles, Theme::i()->css( 'flags.css', 'core', 'global' ) ); } }If you want to load your JS in a specific location, you can use: public function onFinish() : void { if( Dispatcher::hasInstance() AND Dispatcher::i()->checkLocation( 'front', 'app', 'module', 'controller' ) AND isset( Request::i()->id ) ) { ... } }
April 3Apr 3 Community Expert @Adriano Faria The checkLocation() function already does a hasInstance() check by itself. You can skip it. 😉
April 3Apr 3 Community Expert @Adriano Faria The checkLocation() function already does a hasInstance() check by itself. You can skip it. 😉Old habits.