自定义节点模板(内容类型)在drupal 7上不起作用

自定义节点模板(内容类型)在drupal 7上不起作用,drupal,themes,Drupal,Themes,在将以下代码应用到template.php之后,定制节点模板在Drupal7上不起作用。例如,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 "

在将以下代码应用到template.php之后,定制节点模板在Drupal7上不起作用。例如,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;
  } 
}       
如果我删除上面的代码,节点--article.tpl.php正在接收,但页面--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;
  } 
}       

我假设它应该选择页面--article.tpl.php,然后选择节点--article.tpl.php(如果存在)。这个假设是错误的吗?

上面的代码和您的假设是正确的。我试着在我的本地应用程序中使用上面的代码,它工作得很好,因此它将
page--article.tpl.php
用作page-tpl,而对于node-tpl则使用
node--article.tpl.php

检查步骤:

  • 在template.php中编写的hook_preprocess_页面将始终占据优先权

  • 我认为Drupal应该选择page-article.tpl.php和node-article.tpl.php,如果两者都存在的话。根据你的回答,Drupal似乎只会选择其中一个,即使它们都存在?是的,需要两个tpl,一个是自定义页面。tpl和自定义节点tpl。好的,但我的Drupal不是这样工作的。你有什么线索吗?在template.php文件中,它只有上述函数。在页面--article.tpl.php文件中,此变量应为
    $page['content']
    ,inturns将其称为自定义节点tpl。我建议您复制bartick的page.tpl中的所有内容,并将其粘贴到自定义tpl文件中,这同样适用于自定义节点tpl(bartick node.tpl=>custom node tpl)。做一些改变,看看这些改变是否发生了。我刚才用了“”。非常感谢。