该页面的路径别名是 /annual-reports/2012。我在主题 template.php 文件中设置了以下内容:
function tcm_preprocess_page(&$variables, $hook) {
$alias = drupal_get_path_alias($_GET['q']);
$alias = explode('/', $alias);
$template_filename = 'page';
foreach ($alias as $path_part) {
if(is_numeric($path_part)){
$variables['theme_hook_suggestions'][] = $template_filename . '__%';
}
$template_filename = $template_filename . '__' . $path_part;
$variables['theme_hook_suggestions'][] = $template_filename;
}
print_r("<!--\n");
print_r($variables['theme_hook_suggestions']);
print_r("\n-->\n");
}
当我加载页面时,它没有加载正确的模板。如果您注意到我将建议数组输出到评论以确保建议适当的模板。它输出以下内容:
<!--
Array
(
[0] => page__node
[1] => page__node__%
[2] => page__node__207
[3] => page__annual-reports
[4] => page__annual-reports__%
[5] => page__annual-reports__2012
)
-->
我有一个名为 page--annual-reports--%.tpl.php 的模板文件。然而,它正在加载基本页面--node.tpl.php。我错过了什么?