1

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?

2
  • 2
    Note there is now a dedicated ExpressionEngine Q&A site where you can post your question and will be more likely to receive an answer. Commented Dec 15, 2012 at 23:38
  • excellent, didnt know about that. Im pretty sure load_package_js should do it but im getting errors.. Commented Dec 16, 2012 at 11:20

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

Ah, OK. I'm sure that you've double-checked that you can load the .js directly in your browser in order to verify that the web server can actually get it. Otherwise, you might want to follow @adrian-macneil's suggestion above.
yeah thanks anyway though :) will accept this answer as it works with modules.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.