tags:

views:

17

answers:

2

Hi,

I have the following javascript to embed a flash in my page.tpl.php

                         <script type="text/javascript">
                            <!--
                            var flashvars = {
                                xmlUrl: "xml/banner.xml"    //Use to change XML filename or location
                            };
                            var params = {
                                scale: "noscale",
                                menu: "false",
                                bgcolor: "#666666"
                            };
                            var attributes = {
                                id: "banner_swf",
                                name: "banner_swf"
                            };
                            swfobject.embedSWF("banner.swf", "banner_div", "873", "300", "4", "swfobject/expressInstall.swf", flashvars, params, attributes);
                            //-->
                        </script>

The problem, now all the xml and swf file referred in that script is under 'rotator' directory inside my 'customtheme' directory. How should I change the paths?

Thank you for the help! Robert

A: 

To make a path to your theme you can do:

<?php $theme_path = $base_path . path_to_theme(); ?>

Then you could use that later on.

Now if you want to make things a bit more pretty, you should move all this javascript into a js file and add it in your theme's .info file. That would make drupal to minify and cache it.

What you would need to do then, would be to add the path to your javascript, and that is what the global Drupal js variable is for. You could do this in your preprocss page hook.

function my_theme_preprocess_page(&$vars) {
  drupal_add_js(array('myTheme' => array('themePath' => $vars['base_path'] . path_to_theme()), 'setting');
}

Then in your js file you could get that variable:

var path = Drupal.settings.myTheme.themePath;

To make things real Drupal like you should do all of your javascript in a behavior, that get's executed once the page has loaded:

Drupal.behaviors.myThemeAddFlash = function () {
  // Do your thing here
}
googletorp
thanks for the help! I've made it work, have not tried it this way, though. Thanks!
Robert A Henru
A: 

I checked with the flash author, and they asked me to add base: parameter in var params to specify the base folder where I can find all the flash files. At the end, here is what I did to make it work in drupal.

                            <script type="text/javascript">
                            <!--
                            var flashvars = {
                                //xmlUrl: "path/to/xml/filename.xml"    //Use to change XML filename or location
                            };
                            var params = {
                                base: "<?php print $base_path.$directory."/" ?>rotator/",
                                scale: "noscale",
                                menu: "false",
                                bgcolor: "#666666"
                            };
                            var attributes = {
                                id: "banner_swf",
                                name: "banner_swf"
                            };
                            swfobject.embedSWF("<?php print $base_path.$directory."/" ?>rotator/banner.swf", "banner_div", "876", "300", "4", "swfobject/expressInstall.swf", flashvars, params, attributes);
                            //-->
                        </script>
Robert A Henru