2010-08-27 34 views
1

我有以下的JavaScript嵌入閃存在我的page.tpl.php中Drupal的路徑閃存資源

      <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> 

的問題,現在都在該腳本提到的XML和SWF文件是在「轉子」我的'customtheme'目錄內的目錄。我應該如何改變路徑?

謝謝你的幫助! 羅伯特

回答

1

我用閃光燈筆者檢查,他們問我加羣:參數VAR PARAMS指定基文件夾在哪裏可以找到所有的Flash文件。最後,這是我爲了在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> 
0

爲了讓你的主題的路徑,你可以這樣做:

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

然後,你可以使用以後。

現在,如果你想讓事情變得更漂亮一些,你應該將所有這些javascript移動到一個js文件中,並將它添加到你的主題的.info文件中。這將使drupal縮小並緩存它。

你需要做什麼然後,將路徑添加到您的JavaScript,這就是全球Drupal js變量的用途。您可以在預處理頁面鉤子中執行此操作。

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

然後文件,你可以得到該變量:

var path = Drupal.settings.myTheme.themePath; 

爲了讓事情真正的Drupal像你應該做你的JavaScript的行爲,即獲得的執行一次在頁面加載:

Drupal.behaviors.myThemeAddFlash = function() { 
    // Do your thing here 
} 
+0

感謝您的幫助!雖然我已經做到了,但還沒有嘗試過。謝謝! – 2010-08-28 01:04:58