Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID Sign In with Twitter

Categories

In this Discussion

Who's Online 7

Zvonkoericgillettelucperegrine +3 guests

Best way to include custom javascript into Vanilla 2

I'm trying to include a custom .js file into Vanilla 2 but i don't want to modify any of the core files like class.vanillacontroller.php. Has anyone done this successfully?

Tagged:

Comments

  • Posts: 6
    Note, i found one way that worked, its not exactly what i wanted but if you include a link to your .js file in your default.master.php it will work. But i'm still looking for a way to include a .js in the theme folder...
  • Posts: 1,587
    You can add a plugin class to a theme to add the js file. Let's assume your theme is called Patric. Do the following:
    1. Add your custom.js to /themes/Patric/js/custom.js
    2. Create a file called /themes/Patric/class.patricthemehooks.php
    3. Add the following to the php file:

      <?php if (!defined('APPLICATION')) exit();

      class PatricThemeHooks implements Gdn_IPlugin {

      public function Base_Render_Before($Sender) {
      $Sender->AddJsFile('custom.js');
      }
      }
    Themes are always searched for js and css files first so your custom.js will always be given the highest priority.

    Vanilla co-founder

  • Thanks Todd,

    This will be very useful :-)
Sign In or Register to comment.