Hello there, community!
So, the title really says it all. I need to make a plugin, that allows to me load a specific .js file into the template, and run it on every page that the plugin is enabled on. I decided to try and build a generic plugin after looking at several other different plugins that, amongst other things, loads a .js file.
Now, i build up the plugin in a fairly staight forward manner, and with all the proper files (locale files, index, plugin.inc.php file, version file, and a folder containing my js file). The interesting part is the plugin.inc.php file where I build in the functionality as it’s done in the other plugins I’ve looked into. The new added functionality in the plugin.inc.php file is my problem. I have the getName and getDescription functions aswell, and they work seeing as name and description is displayed properly on the plugin-page. The new added stuff however, does not work properly.
I have a register function as follows:
function register($category, $path) {
$success = parent::register($category, $path);
if ($success && $this->getEnabled()) {
HookRegistry::register(‘TemplateManager::display’, array($this, ‘callback’));
}
return $success;
}
and the callback function is as follows:
function callback($hookName, $args) {
$templateMgr = TemplateManager::getManager();
$templateMgr->addJavaScript(
‘cookiePolicy’,
$request->getBaseUrl() . ‘/’ . $this->getPluginPath() . ‘/js/cookiePolicy.js’
);
}
Now, this does nothing at all. I get no php errors, nor do i get the script onto the site, nothing just happens. The plugin is enabled, and if i do something weird in the php code, i do get an error that crashes the plugin-page, so I know the plugin is enabled and executed properly. But nothing else happens.
I was hoping someone could point me in the right direction. All i really need is the .js file loaded and executed (which i assume would happen if the file was properly read) on the site that the plugin is enabled on.
Does anyone know how to fix that?
Kind regards,
Jesper.