【发布时间】:2010-07-06 19:25:40
【问题描述】:
如何为我想要的任何节点切换到不同的主题模板文件? 我了解如何为具有“食谱”路径的节点创建子主题,例如 node-recipes.tpl.php。但是我想要控制整个基本模板,如 page.tpl.php。 我可以在 template.php 中使用一些预处理函数吗?
现在我的 template.php 文件中有这个:
function mythemename_preprocess_node(&$vars) {
// template name for current node id
$suggestions = array('node-'. $vars['nid']);
// additional node template names based on path alias
if (module_exists('path')) {
// we already can have a path alias
if (isset($vars['path'])) {
$alias = $vars['path'];
}else{
// otherwise do standard check
$alias = drupal_get_path_alias('node/'. $vars['nid']);
}
if ($alias != 'node/'. $vars['nid']) {
$add_path = '';
foreach (explode('/', $alias) as $path_part) {
$add_path .= !empty($path_part) ? $path_part.'_' : '';
$suggestions[] = 'node-'. $add_path;
}
// adding the last one (higher priority) for this path only
// node-some-long-path-nofollow.tpl.php (not for anchestors)
$suggestions[] = end($suggestions) .'-nofollow';
}
$suggestions=array_map(stripTag, $suggestions);
//print_r($suggestions);
}
$vars['template_files'] = isset($vars['template_files']) ? array_merge($vars['template_files'], $suggestions) : $suggestions;
}
谢谢
【问题讨论】:
标签: drupal templates themes overriding preprocessor