我构建了一个名为ap_news的模块,它创建了几个模块。我在“sites/all/modules/custom/ap_news/theme /”中有我的自定义块模板文件。这一切都有效,但我希望设计师能够通过将这些文件的副本放在“sites/mysite.com/themes/theme428/templates/block”或“sites/mysite.com/themes/theme428”中来覆盖这些tpl文件/ templates/ap_news“ 所以我想Drupal首先查看网站主题文件夹,如果找不到,请查看我的模块主题文件夹。我试过了,但它只使用我模块中的那个。 这里是我的块和主题代码:Drupal 6重写模块模板文件
function ap_news_block($op = 'list', $delta = 0, $edit = array()) {
switch ($op) {
case "list":
// Generate listing of blocks from this module, for the admin/block page
$block = array();
$block['ap_news_national_news']['info'] = t('National news');
$block['ap_news_national_news']['cache']=BLOCK_NO_CACHE;
$block['ap_news_world_news']['info'] = t('World news');
$block['ap_news_world_news']['cache']=BLOCK_NO_CACHE;
return $block;
break;
case "view":
switch ($delta) {
case 'ap_news_national_news': // block-ap_news_national_news.tpl.php
// Generate our block content
$html = ap_news_nationalNews();
$block['subject'] = 'National News';
$block['content'] = $html;
$data = new stdClass(); $data->module = 'ap_news'; $data->content = $html; $data->delta = $delta; $data->subject = 'National News';
$block['content'] = theme('block-'.$delta, $data);
break;
//--------------------
case 'ap_news_world_news': // block-ap_news-world_news.tpl.php
$data = ap_news_allNews_block('WORLD', APNEWS_CID_WORLD_NEWS, 4);
$block['subject'] = 'World News';
$block['content'] = theme('block-ap_news-all_news', $data, base_path().APNEWS_PATH_WORLD_NEWS, 'World News', 'worldNews');
break;
}
}
return $block;
}
function ap_news_theme() {
return array(
'block-ap_news-all_news' => array(
'template' => 'theme/block-ap_news-all_news',
'arguments' => array('data' => NULL, 'path' => NULL, 'sectionName' => NULL, 'sectionId' => NULL),
),
'block-ap_news_national_news' => array(
'template' => 'theme/block-ap_news_national_news',
'arguments' => array('block' => NULL),
),
);
}
UPDATE: 我创建了一个功能,现在寻找的文件。
'block-ap_news-national_news' => array(
'template' => 'block-ap_news-national-news',
'arguments' => array('block' => NULL),
'path' => ap_news_templatePath('block', 'block-ap_news-national-news', 'ap_news'),
),
/*
* Find the template paths.
* First look in the sites custom theme template folder (/themes/theme428/templates/ap_news),
* then in sites normal theme template folder,
* then in the modules folder
*/
function ap_news_templatePath($type, $template, $custom=''){
$siteThemePath = path_to_theme() . '/templates/' . $type. '/';
$siteCustomThemePath = path_to_theme() . '/templates/' . $custom. '/';
$moduleThemePath = drupal_get_path('module', 'ap_news') . '/theme/';
if(file_exists($siteCustomThemePath . $template . '.tpl.php')){
return $siteCustomThemePath;
}elseif(file_exists($siteThemePath . $template . '.tpl.php')){
return $siteThemePath;
}else{
return $moduleThemePath;
}
}
你可以发布你的'hook_theme()'实现块主题吗?另外,哪个Drupal版本? – 2012-01-09 19:50:35
我正在使用Drupal 6.20。我在原始文章中有hook_theme,除非我错过了一些东西。我不知道我需要一个单独的主题钩为我的块。我错过了什么?谢谢 – EricP 2012-01-09 19:59:02
对不起,我一开始没注意到'hook_theme()'代码。 – 2012-01-09 20:02:41