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
1 hour ago, Esther E. said:

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
2 hours ago, CleanTalk said:

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

  • Community Expert
14 minutes ago, teraßyte said:

@Adriano Faria The checkLocation() function already does a hasInstance() check by itself. You can skip it. 😉

Old habits.

  • Author

Thank you so much. Loader extension is the solution!

Recently Browsing 0

  • No registered users viewing this page.