0

I am very much a beginner with scripting, drupal theming, etc and I cannot figure out how to deal with the following "problem":

I have signed up my site with a media network, which will handle all the ad revenue making. They have given me a custom .js script and shared the following generic instructions:

  • upload the .js script to the website - That I can do. :)
  • paste <script type="text/javascript" src="path to script/scriptname.js"></script> into the <head></head> area of all pages on the website. I guess this means editing the page.tpl.php file of the theme I am using to add this piece of code. However, I do not know how to do this, in a way that works well, without breaking the theme and how the website is displayed.
  • call the script into specific ad areas/blocks using something similar to this: <script>scriptname.display(options = {'width':635, 'ad_width':190, 'max_ads':3, ‘descFontSize':15, 'linkFontSize':12, 'linkFontColor':'999999'});</script> Here, I am not sure if it is enough to simply copy/paste this code, while using the correct name of the script file.

The trouble is, these guys are used to working with WordPress and they won't advise me on how to set things up in Drupal. So... I appreciate any advice you can give.

PS: I am using the latest version of Drupal 7.

1

After you do what dkiscool said you'll need to create a block, add the required code (Name.display(...)) to it and add the block to the region where you want it to show.

Be careful when you add javascript to a block. You'll need to disable any rich text editor to avoid having the characters html encoded and also choose an input filter that does not html encode or transform newlines into page breaks or paragraphs (the php filter works but for security reasons you might want to add a new filter instead of using the php one).

  • Thanks. It worked. I enabled the PHP filter, used the code and the ads are displayed correctly. Appreciate both your help. – Corporate Geek Jan 16 '12 at 15:52
2

Upload your .js file in your theme directory. In your theme's .info file add scripts[] = path/file_name.js as follows.

enter image description here This will include the .js file in each page of your site. Path of the .js file is relative to the .info file.

  • Thanks a lot. That helped add the js file to each page. What I don't understand now is why the ads are not shown in the blocks where I add the call script with the given parameters. It simply shows an empty block. :( – Corporate Geek Jan 13 '12 at 23:22
  • I just realized, they say to call a variable from the script using something like: <script>variable Name.display(options = {'width':635, 'ad_width':190, 'max_ads':3, ‘descFontSize':15, 'linkFontSize':12, 'linkFontColor':'999999'});</script> – Corporate Geek Jan 13 '12 at 23:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.