在 template.php 文件中,我插入了以下代码: 我在网上发现了一个提供代码的教程,但我对如何让它工作感到困惑。
我复制了以下代码,并将其插入主题 HTML5_base 的 template.php 中。 我复制了 page.tpl.php 文件并创建了自定义页面 - page-gallery.tpl.php 和 页articles.tpl.php 即可。我在文件中插入了一些文本,只是看到我已经导航到了更改的页面。看起来Drupal没有识别gallery.tpl.php和page-articles.tpl.php。
在template.php中有以下功能:
html5_base_preprocess_page()
html5_base_preprocess_node()
html5_base_preprocess_block()
在本教程中,它使用了这些功能:
phptemplate_preprocess_page()
phptemplate_preprocess_block()
phptemplate_preprocess_node()
function phptemplate_preprocess_page(&$vars)
{
//code block from the Drupal handbook
//the path module is required and must be activated
if(module_exists('path'))
{
//gets the "clean" URL of the current page
$alias = drupal_get_path_alias($_GET['q']);
$suggestions = array();
$template_filename = 'page';
foreach(explode('/', $alias) as $path_part)
{
$template_filename = $template_filename.'-'.$path_part;
$suggestions[] = $template_filename;
}
$vars['template_files'] = $suggestions;
}
}
function phptemplate_preprocess_node(&$vars)
{
//default template suggestions for all nodes
$vars['template_files'] = array();
$vars['template_files'][] = 'node';
//individual node being displayed
if($vars['page'])
{
$vars['template_files'][] = 'node-page';
$vars['template_files'][] = 'node-'.$vars['node']->type.'-page';
$vars['template_files'][] = 'node-'.$vars['node']->nid.'-page';
}
//multiple nodes being displayed on one page in either teaser
//or full view
else
{
//template suggestions for nodes in general
$vars['template_files'][] = 'node-'.$vars['node']->type;
$vars['template_files'][] = 'node-'.$vars['node']->nid;
//template suggestions for nodes in teaser view
//more granular control
if($vars['teaser'])
{
$vars['template_files'][] = 'node-'.$vars['node']->type.'-teaser';
$vars['template_files'][] = 'node-'.$vars['node']->nid.'-teaser';
}
}
}
function phptemplate_preprocess_block(&$vars)
{
//the "cleaned-up" block title to be used for suggestion file name
$subject = str_replace(" ", "-", strtolower($vars['block']->subject));
$vars['template_files'] = array('block', 'block-'.$vars['block']->delta, 'block-'.$subject);
}