2016-04-26 75 views
0

我有一個自定義的Drupal主題Starterkit。其中有一個JS文件,我需要獲取當前主題的路徑。例如:Drupal主題消毒路徑

imagesPath: '/sites/default/themes/{{ THEME SANITIZED }}/js/ckeditor_templates/', 

因爲可能會有人把STARTERKIT在

/sites/all/themes/ 

,而不是

/sites/default/themes/ 

我需要的入門套件考慮到這一點。是否有{{}}來獲取創建Starterkit的目錄的路徑?

回答

1

我可以確認Drupal沒有爲路徑提供{{THEME SANITIZED}}。但是你可以通過config.customConfig變量從CKEditor配置文件獲取ckeditor.config.js文件的路徑。因此,我們有足夠的信息來創建主題的路徑。我剛剛刪除了文件名並將其用作路徑。

ekeditor.config.js

CKEDITOR.editorConfig = function(config) { 
    pathToTheme = config.customConfig.substring(0, config.customConfig.lastIndexOf("/")); 
    config.templates_files = [ pathToTheme + '/js/ckeditor_templates/ckeditor_templates.js' ]; 
    yada yada yada, 
} 

ckeditor_templates.js

CKEDITOR.addTemplates('default', { 
    imagesPath: pathToTheme + '/js/ckeditor_templates/', 
    templates: [yada yada yada], 
} 
}); 
1

你可以把路徑用drupal_add_jsdrupal_get_path像這樣在你的主題的settings.php或template.php文件中的自定義設置:

$theme_path = drupal_get_path('theme', 'my-theme'); 
drupal_add_js(array('myCustomSetting' => array('path' => $theme_path)), 'setting'); 

然後,在JavaScript文件,你可以參考像設置:

Drupal.settings.myCustomSetting + '/js/ckeditor_templates/' 

我建議讓Drupal的構建路徑爲你,而不是試圖烘烤在

關於動態構建子主題時可用的變量,我真的不知道。我所有的優勢都是你提到的{{主題SANITIZED}}值。

我還沒有測試過上面的東西,但是像它這樣的東西應該工作得很好。