Search code examples
expressionengine

Expression Engine add javascript to head


I have been struggling with this for a while now and am stuck I am writing an extension for Expression Engine 2 (not a module) and need to add a script tag to the header of the page.

I have tried:

$script = "<script type='text/javascript'>alert('added');</script>";
$this->EE->cp->add_to_head($script);

but im guessing this only works when its a module, i have also tried:

$this->EE->cp->load_package_js('file');

but i get the following error:

Call to a member function plugin() on a non-object in expressionengine/libraries/Cp.php on line 766

I have also tried using the hook cp_js_end which loads the file but its loaded after everything else thus it does not work as intended.

Any Ideas?


Solution

  • I think Low has your answer . In summary, you'll need file to be in a directory javascript in your package directory.