You are viewing the PKP Support Forum | PKP Home Wiki

plugin insert javascript in header

OJS development discussion, enhancement requests, third-party patches and plug-ins.

Moderators: jmacgreg, btbell, michael, bdgregg, barbarah, asmecher

Forum rules
Developer Resources:

Documentation: The OJS Technical Reference and the OJS API Reference are both available from the OJS Documentation page.

Git: You can access our public Git Repository here. Comprehensive Git usage instructions are available on the wiki.

Bugzilla: You can access our Bugzilla report tracker here.

Search: You can use our Google Custom Search to search across our main website, the support forum, and Bugzilla.

Questions and discussion are welcome, but if you have a workflow or usability question you should probably post to the OJS Editorial Support and Discussion subforum; if you have a technical support question, try the OJS Technical Support subforum.

plugin insert javascript in header

Postby MarieNyst » Thu Dec 13, 2012 10:06 am

Hi !

I would like to insert javascript in header. For this, I've my register function here :

Code: Select all
function register($category, $path) {
        if (parent::register($category, $path)) {
              if ($this->getEnabled()) {
                // Insert header on every header (callback function checks if it addition is really need)
                HookRegistry::register('TemplateManager::display',array(&$this, 'callback'));
            return true;
        return false;

and my callback function here :

Code: Select all
function callback($hookName, $args) {
      //First argument is a TemplateManager object.
        $templateMgr =& $args[0];

        //Getting some context.
        $journal = &Request::getJournal();
        $journalId = $journal->getJournalId();
        $page = Request::getRequestedPage();
        $op = Request::getRequestedOp();
        $currentJournal = $templateMgr->get_template_vars('currentJournal');

        //Add additionalHeader just in a few pages of the current Journal:
        if (!empty($currentJournal))
         //Extending template's head:
            $additionalHeadData = $templateMgr->get_template_vars('additionalHeadData');
            $additionalHeadData .= "\n\n        <!-- Keywords Headers -->\n";
            $additionalHeadData .= $templateMgr->fetch('./plugins/generic/keywords/generatedFiles/keywordsChoiceScript.js.tpl');
            $additionalHeadData .= "        <!-- Keywords Headers -->";

            $templateMgr->assign('additionalHeadData', $additionalHeadData);
        return false;

and my script here :

Code: Select all
{literal}<script type="text/javascript" src="http://code.jquery.com/jquery-latest.pack.js"></script>
 a {color:#333; text-decoration:none}
 a:hover {color:#ccc; text-decoration:none}

   <!-- style doesn't mater -->
   function keywordsSetOptions(chosen) {
<!-- script that I've already tested-->
$(document).ready(function() {
    <!-- some other things I've tested -->

Nothing happens, my headers are still the same... Did I make it wrong ?
Posts: 24
Joined: Thu Nov 29, 2012 9:35 pm

Re: plugin insert javascript in header

Postby asmecher » Thu Dec 13, 2012 11:55 am

Hi MarieNyst,

You probably need to register the plugin in the database; have a look at http://pkp.sfu.ca/support/forum/viewtopic.php?f=9&t=7909#p30755 or http://pkp.sfu.ca/support/forum/viewtopic.php?f=9&t=9067#p35235 for some further discussion. There is also some howto documentation at http://pkp.sfu.ca/wiki/index.php/Writing_a_Block_Plugin.

Alec Smecher
Public Knowledge Project Team
Posts: 10015
Joined: Wed Aug 10, 2005 12:56 pm

Re: plugin insert javascript in header

Postby MarieNyst » Fri Dec 14, 2012 8:44 am

I made the upgrade and it works.

thank you
Posts: 24
Joined: Thu Nov 29, 2012 9:35 pm

Return to OJS Development

Who is online

Users browsing this forum: No registered users and 1 guest