試試這個 首先創建.module文件的菜單
function MYMODULE_menu()
{
$items['Demo'] =array(
'title' => 'Demo Page',
'page callback' => 'demo_page', // call a function
'access arguments' => array('access content'),
);
return $items;
}
之後,你有創建一個功能
function demo_page()
{
$select = db_select('node', 'n');
$select = $select->fields('n', array('id'))
->extend('PagerDefault');
$queried_nodes = $select->execute()
->fetchAllAssoc('id');
$pager = theme('pager');
return theme('demo_template', array('nodes' => $queried_nodes , 'pager' => $pager)); // call a theme or you have no pass any argument in theme to change a 'nodes'=> NULL or 'pager'=>NULL
}
後,我已創建一個主題功能
function MYMODULE_theme()
{
return array(
'demo_template' => array(
'template' => 'demo-page',//this is file name of template file
'variables' => array('nodes' => NULL,'pager' => NULL), //this is pass avarible of templates file
'path' => drupal_get_path('module', 'MYMODULE_NAME').'/template' // set a path of file
),
);
}
後,你有創造這樣的網站演示page.tpl.php中的文件名/所有/模塊/ MYMODULENAME /模板/
和清除緩存
我想我已經想通了這一點。 –
我昨晚在學習如何爲Drupal編程,我需要放棄基於D6的方法並重新開始。 頁面處理程序需要返回一個表單元素數組,並且它們應該返回到調用函數而不是直接打印,因此不需要直接調用theme()函數。在hook_theme函數中,我可以設置要使用的模板。 我會稍後發佈更詳細的解釋,以幫助任何人。 –