Jump to content

Featured Replies

Posted

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.

  • 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.

  • 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?

  • 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 ) )
		{
			...
		}
	}

  • Author

Thank you so much. Loader extension is the solution!

Recently Browsing 0

  • No registered users viewing this page.