2013-05-16 29 views
0

我只是試圖創建一個模塊名稱mymodule,並試圖將主題應用於drupal6中的該模塊。如何在drupal6中創建自定義主題並將模板應用到它

我已經爲我的模塊添加了.info文件,並在我的主題文件夾中創建了mymodule.tpl.php文件,並從管理員啓用了該模塊。但是當我通過url訪問模塊時,它會返回白頁。

我mymodule.module.php文件包含

function mymodule_menu() { 
    $items = array(); 

    $items['mymodule'] = array(
    'page callback' => 'mymodule_page', 
    'access arguments' => array('access content'), 
    'type' => MENU_CALLBACK, 
); 

    return $items; 
} 

function mymodule_page() { 
    $result = db_query('SELECT * from node'); 
    return theme('mymodule', array('output' => $result)); 
} 

function mymodule_theme() { 
    $content = array(
    'custom' => array(
     'arguments' => array('output' => 'NULL'), 
     'template' => path_to_theme() . '/mymodule', 
     'path' => '/' 
    ), 
); 
    return $content; 
} 

我不知道爲什麼主題不會應用到我的模塊。請幫忙。

回答

1

對於我看到的問題是pathtemplate鍵。

從Drupal的文檔(http://api.drupal.org/api/drupal/developer%21hooks%21core.php/function/hook_theme/6):

路徑:覆蓋該文件的路徑被使用。通常將使用模塊 或主題路徑,但如果該文件不在默認路徑 中,請將其包括在此處。此路徑應該相對於Drupal根目錄 目錄。

所以你要覆蓋與/模塊路徑,這將導致在Drupal的根文件夾(其中沒有mymodule.tpl.php)。嘗試刪除path密鑰。

此外,template關鍵應該只有模板文件名。 Docs:

template:如果指定,則此主題實現爲模板,而 這是沒有擴展名的模板文件。

所以嘗試刪除path_to_theme一部分,你必須給模板文件名,而不是完整路徑模板(您正在使用的path_to_theme功能提供)。

希望這將幫助!

+0

它工作的感謝.. – anoop

+0

很高興我可以幫助! :) – endorama

+0

Yah它爲我工作。目前我只能在page.tpl.php的內容區域查看此內容。我如何更改整個模板的主題?這個問題,我已經在這裏添加http://stackoverflow.com/questions/16609463/how-can-i-change-the-entire-template-of-the-page-according-to-module-in-drupal6 – anoop

相關問題