如Drupal 7模板建议中所述,Drupal 7默认使用的页面模板建议是page-[front | internal / path] .tpl.php。
对于http://www.example.com/node/1/edit上可见的页面,Drupal将寻找以下模板文件:
- 页面-节点--edit.tpl.php
- 页面--node--1.tpl.php
- 页面--node.tpl.php
- page.tpl.php
要添加其他建议,您的主题应实现template_preprocess_page()并在中添加新建议$variables['theme_hook_suggestions']
($variables
是通过引用传递给函数的变量)。
如果这样做,那么未使用建议的模板文件的唯一原因是因为该文件的名称不正确:例如,在该页面显示书页的情况下,模板文件应为page--book.tpl .php。您可以更改主题的代码,如果找不到页面–book.tpl.php之类的模板,则可以使用页面-node-type.tpl.php模板。
还要注意的是,在theme_get_suggestions()(由template_preprocess_page()调用的函数)中,连字符被代替_
,反之亦然。在功能代码中报告的注释中解释了这样做的原因。
// When we discover templates in drupal_find_theme_templates(),
// hyphens (-) are converted to underscores (_) before the theme hook
// is registered. We do this because the hyphens used for delimiters
// in hook suggestions cannot be used in the function names of the
// associated preprocess functions. Any page templates designed to be used
// on paths that contain a hyphen are also registered with these hyphens
// converted to underscores so here we must convert any hyphens in path
// arguments to underscores here before fetching theme hook suggestions
// to ensure the templates are appropriately recognized.
$arg = str_replace(array("/", "\\", "\0", '-'), array('', '', '', '_'), $arg);