2008-11-19 39 views

回答

19

這應該工作(doc):

global $theme; 
$path = drupal_get_path('theme', $theme); 

// there's also a $theme_path global 

global $theme_path; 
+0

嗨歐文感謝info – 2010-03-22 12:34:09

+0

最好使用`path_to_theme()`,而不是使用`$ theme_path`。 – kiamlaluno 2010-09-29 20:53:59

0

在Drupal的5,你可以簡單地使用:path_to_theme()

這會給你的Drupal的根目錄的完整路徑特定主題目錄。請注意,它不包含尾部斜線。

在Drupal 6中,它的行爲有點不同。如果您從網頁中調用它,它會調用任何正在進行主題的任何操作......無論這是您的主題,模塊等。以下是來自API文檔的重要報價:

它可以指向以活動主題或 模塊處理主題 實施。例如,當 調用範圍內調用 時,它將取決於主題函數的處理位置。如果從模塊實現 ,則將 指向該模塊。如果從活動主題實施 ,則它將指向 到活動主題。當主叫號碼 超出主叫範圍 時,它將始終指向主動 主題。

來源:http://api.drupal.org/api/function/path_to_theme

9

在D6 path_to_theme()可能不會在你這取決於你如何使用它期待的方式表現。如果你在任何主題預處理函數之外使用它,那麼它可能會給你你想要的,但是如果它在一個模塊的主題/預處理鉤子函數的上下文中被調用,它將指向模塊路徑宣佈了主題。

Ex。如果我有一個主題「my_theme」和我的模塊「my_module」,它使用預處理鉤子重寫論壇主題,請在我的模塊中調用path_to_theme():例如my_module_preprocess_forums()...將返回「論壇」,而不是人們所期望的「my_theme」。

如果你問我很果味。

4

在Drupal 7中,爲獲取當前主題的路徑,我們可以使用: path_to_theme()函數。

0

對於D8,主題文件夾可以在預處理功能:

function hook_preprocess_page(&$variables) { 
    $variables['some_logo_file'] = "/{$variables['theme']['path']}/images/logo.png"; 
} 

page.html.twig:

<img src="{{ logo_src }}"> 
1

在Drupal的爲8個

global $base_url; 
$theme = \Drupal::theme()->getActiveTheme(); 
$image_url = $base_url.'/'. $theme->getPath() .'/images/image.jpg'; 
相關問題