We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Newbie: How to add a piece of JS in every page.

Development and Programming

swekey's avatar
swekey
4 posts
15 years ago
swekey's avatar swekey

Hello all,

I’ m new to EE and i need to write an extension that adds a few lines of JavaScript to EVERY pages (even the system/login page), whatever the theme is.

I checked the available hooks and I did not find anything that could suit my needs :-(

Do you have any hint for me ?

Regards,

Luc

       
johnwbaxter's avatar
johnwbaxter
651 posts
15 years ago
johnwbaxter's avatar johnwbaxter

If it’s the cpanel then make an accessory and use:

$this->EE->javascript->output('');
$this->EE->javascript->compile();

As for the login page you may have to manually change some view files there.

       
ender's avatar
ender
1,644 posts
15 years ago
ender's avatar ender

for the front-end pages of a site, I’d suggest making a module/plugin that could output the necessary javascript via a tag added by the programmer/designer of the site to a global header template:

includes/header template (for example):

<html>
<head>
    <title>blah blah</title>
    {exp:some_plugin:js_includes}
</head>

I agree that an accessory like audiopleb mentioned is probably the best option for the control panel, I’m not aware of any hooks that would let you run code on every CP page. The login page will probably require a “hack” to the necessary view or core files, but should be fairly minor I’d think.

       
swekey's avatar
swekey
4 posts
15 years ago
swekey's avatar swekey

I checked how the Google Analitics extention works, and you must to add a tag in your templates to make it works. It is not very user friendly.

Do you know if there is a central place in the code where we can add a hook that will let an extension post process the generated HTML ?

Almost all of the open source project I know (Joomla, Drupal, Magento, PhpMyAdmin, PhpBB, vBulletin, Wordpress…) have this hook.

Luc

       
ender's avatar
ender
1,644 posts
15 years ago
ender's avatar ender

I don’t believe that exists in EE. People familiar with EE won’t be taken aback by having to include the required tag in their <head>… they actually might wonder how your product works if it “magically” inserts the required code, to be honest.

       
swekey's avatar
swekey
4 posts
15 years ago
swekey's avatar swekey

So I’ll try to do it using the tag.

Thanks,

Luc

       
swekey's avatar
swekey
4 posts
15 years ago
swekey's avatar swekey
I don’t believe that exists in EE. People familiar with EE won’t be taken aback by having to include the required tag in their <head>… they actually might wonder how your product works if it “magically” inserts the required code, to be honest.

I finally found a way do it:

My extension installs a CI hook ($hook[‘display_override’) and it works perfectly.

And idea: Why not implement EE hooks that just maps CI hooks ?

Luc

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.