自定义节点模板(内容类型)不适用于 drupal 7
custom node template (content type) is not working on drupal 7
将以下代码应用到 template.php 后,自定义节点模板不适用于 Drupal 7。例如,node--article.tpl.php
function jstheme_preprocess_page(&$variables) {
if (isset($variables['node']->type)) {
// If the content type's machine name is "my_machine_name" the file
// name will be "page--my-machine-name.tpl.php".
$variables['theme_hook_suggestions'][] = 'page__' . $variables['node']->type;
}
}
如果我删除上面的代码,node--article.tpl.php 正在获取但不是 page--article.tpl.php
我假设它应该选择 page--article.tpl.php 然后 node--article.tpl.php 如果它们存在的话。这个假设是错误的吗?
上面的代码和你的假设是正确的。我尝试在我的本地使用上面的代码它工作正常,结果它需要 page--article.tpl.php
作为页面 tpl 而对于节点 tpl 它需要 node--article.tpl.php
.
检查步骤:
- hook_preprocess_page写成template.php永远优先
将以下代码应用到 template.php 后,自定义节点模板不适用于 Drupal 7。例如,node--article.tpl.php
function jstheme_preprocess_page(&$variables) {
if (isset($variables['node']->type)) {
// If the content type's machine name is "my_machine_name" the file
// name will be "page--my-machine-name.tpl.php".
$variables['theme_hook_suggestions'][] = 'page__' . $variables['node']->type;
}
}
如果我删除上面的代码,node--article.tpl.php 正在获取但不是 page--article.tpl.php
我假设它应该选择 page--article.tpl.php 然后 node--article.tpl.php 如果它们存在的话。这个假设是错误的吗?
上面的代码和你的假设是正确的。我尝试在我的本地使用上面的代码它工作正常,结果它需要 page--article.tpl.php
作为页面 tpl 而对于节点 tpl 它需要 node--article.tpl.php
.
检查步骤:
- hook_preprocess_page写成template.php永远优先