Asset path with Multilingual set

Adding this note in case someone else hits a similar problem.

I implemented a plugin which needs to load a JS file. Initially, I added the js file in onPluginsInitialized with the line (datatables being the plugin)

$this->grav['assets']->addJs( 'plugin://datatables/assets/datatables.min.js');

This worked fine until I changed the site to multilingual, and then the js file was no longer loaded.

The problem was that the Grav System was loading from

<pathtoplugin>/en-gb/datables/assets/datatables.min.js

Note the en-gb, which is added for multilingual sites.

My solution, which I think is a correct one, and something that may be should be documented in the Multilingual section, is

  • Register a callback to onAssetsInitialized
  • create a function onAssetsInitialized
  • add the assets in that function.