By skullo on
Hi everyone! I'm new to drupal & I'm loving every bit of it.
I just ran into a little issue recently though. I cannot figure out how to add
tags to the header of the page. The script I'm looking to embed is this:<script type="text/javascript" src="scripts/swfobject/swfobject.js"></script>
<script type="text/javascript">
var flashvars = {};
flashvars.cssSource = "piecemaker.css";
flashvars.xmlSource = "piecemaker.xml";
var params = {};
params.play = "true";
params.menu = "false";
params.scale = "showall";
params.wmode = "transparent";
params.allowfullscreen = "true";
params.allowscriptaccess = "always";
params.allownetworking = "all";
swfobject.embedSWF('piecemaker.swf', 'piecemaker', '1000', '600', '10', null, flashvars,
params, null);
</script>
Can anyone tell me where exactly to place this and in which file?
Many Thanks! :)
Comments
It depends on what the code
It depends on what the code you are enabling relates to, and which pages you want it to appear on. Is the script related to your theme - does your theme require it to run? Or is it modular based, and if it is, do you need it to run on every page on the site, or just on certain pages that your module provides? Is it part of a form?
Answer those and it will be easier to explain where the best place to add your script is.
Contact me to contract me for D7 -> D10/11 migrations.
Its an SWF file which appears
Its an SWF file which appears on the home page (in the featured block). The SWF file needs this script to run properly.
Thanks a lot for your help! :)
Its an SWF file which appears
Can you show the code you are using to create the block?
Theme's don't need to supply any template file, they only supply them if they are overriding the the template. Bartik uses the default html.tpl.php, and as such it doesn't add it, Drupal just adds the default one automatically. You can copy html.tpl.php to your theme and it will be used instead of the default Drupal theme.
HOWEVER, scripts shouldn't be added to html.tpl.php. They should be added to the theme's .info file. HOWEVER (again), unless you are adding your .swf file to every page on the site, you shouldn't add it to the .info file. If you give more info about when/where/how the .swf file is being included, I can give you some suggestions on how to add your js.
If you are using a custom content type, you can add the js in .hook_node_load().
Contact me to contract me for D7 -> D10/11 migrations.
possibly use html.tpl.php ?
I'm just starting to play with drupal-7.0 and I'm on the same trail as you .. trying to add swfobject script into <head>
From my reading of forum so far there is a new template file html.tpl.php which allows custom scripts to be added to <head>.
I started by trying to install swfaddress module for flash object embedding but in drupal status report it reads that swfaddress is looking for an older version 2.1 and current version is 2.4.
So I decided to create my own theme (cloned from bartik) and embed swfobject scripts into my custom theme. However there is no html.tpl.php file included in the bartik template.
I'm still trying to embed flash using swfobject.
Where to add script code
I have the same question. To be more specific, I want to add the MediaElement video player. At the www.mediaelementjs.com site they recommend adding some script and div tags to get the player to show up. I want to create a custom page content-type and then add the recommended code to it. What file do I add the code to?
Thanks
If you only want the script
If you only want the script included on certain pages, I think a custom module would work. This would let yo specify which pages the script is loaded:
Note: this assumes swfobject.js is in your module folder in sites/all/modules/YOURTHEME or sites/YOURSITE/modules/YOURTHEME
Alternatively, if you are adding it to a theme and need it on every page. Then you would add the following line to your theme's .info file:
Note: this assumes swfobject.js is in your theme folder in sites/all/themes/YOURTHEME or sites/YOURSITE/themes/YOURTHEME
-= Gerrit Brands
edit customtheme.info vs. html.tpl.php
I've tried adding swfobject script links in the customtheme.info file
scripts[] = js/swfobject/swfobject.js
but after viewing in drupal and inspecting the generated (html) source the script links appear in the <body> instead of <head> and swfobject does not show the flash object. I see instead the alternative text with Adobe download link.
Currently I'm trying out editing html.tpl.php to place script links inside <head<
html.tpl.php
Well editing html.tpl.php .. in a custom theme ... seems to place the javascript correctly inside in <head>
here is some code I added to html.tpl.php
It is still not showing test.swf but this might be due to wrong paths .. at least when I "view html source" in browser I can see the correct position of links in head and body.
Yes! This worked for me!
Yes! This worked for me! Thanks a lot!! :)
tags in html.tpl.php worked like a charm!! Thank you everyone!!! :)Placing the
I finally got my flash object
I finally got my flash object to render by specifying full url's to the swfobject arguments
swfUrl and expressInstallSwfturl
From the swfobject documentation ..
swfobject.embedSWF(swfUrl, id, width, height, version, expressInstallSwfurl, flashvars, params, attributes, callbackFn) has five required and five optional arguments:
But instead of using full url's I'm not sure what relative paths I should use .. is it relative to the templates files location?