Skip to content
Grav 2.0 is officially stable. Read the announcement →
Plugins

Asset path with Multilingual set

Started by Richard Hainsworth 8 years ago · 0 replies · 593 views
8 years ago

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)

PHP
$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

TXT
<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.
last edited 04/06/18 by Richard Hainsworth

Suggested topics

Topic Participants Replies Views Activity
Plugins · by Vladimir Novak, 2 weeks ago
3 291 2 weeks ago
Plugins · by Mathieu Lecouturier, 3 weeks ago
3 277 3 weeks ago
Plugins · by Slebeig, 2 months ago
1 403 2 months ago
Plugins · by Rene, 2 months ago
2 574 2 months ago
Plugins · by Xavier, 3 months ago
2 490 3 months ago