Php 警告:无法在include()中将标量值用作数组
为了给我的站点中的特定页面设置主题,我创建了一个名为node--2.tpl.php的文件。根据我阅读的其他一些教程,我将以下内容添加到我的template.php文件中:Php 警告:无法在include()中将标量值用作数组,php,drupal,drupal-7,drupal-theming,Php,Drupal,Drupal 7,Drupal Theming,为了给我的站点中的特定页面设置主题,我创建了一个名为node--2.tpl.php的文件。根据我阅读的其他一些教程,我将以下内容添加到我的template.php文件中: function mtheme_preprocess_node(&$vars) { if (request_path() == 'node/2') { $vars['theme_hook_suggestions'][] = 'node__2'; } } 在这一页上,我希望显示名为schools_lan
function mtheme_preprocess_node(&$vars) {
if (request_path() == 'node/2') {
$vars['theme_hook_suggestions'][] = 'node__2';
}
}
在这一页上,我希望显示名为schools_landing的区域。因此,节点--2.tpl.php看起来像这样,而不是别的:
<?php print render($page['schools_landing']); ?>
此外,我可以在node--2.tpl.php文件中写入文本,它显示得很好(而不是默认的页面内容),但我根本无法在区域内部获得要渲染的块。如果我将块指定给登录块,则在页面上看不到任何内容
$page
是一个布尔值,而不是数组。这就是您出现该错误的原因。使用以下代码设置它
$variables['page'] = $variables['view_mode'] == 'full' && node_is_page($node);
foreach (system_region_list($GLOBALS['theme']) as $region_key => $region_name) {
if (!isset($variables['page'][$region_key])) {
$variables['page'][$region_key] = array();
}
}
正是hook\u preprocess\u page()
获得了变量$page
,该变量具有您期望的值。包含以下代码
$variables['page'] = $variables['view_mode'] == 'full' && node_is_page($node);
foreach (system_region_list($GLOBALS['theme']) as $region_key => $region_name) {
if (!isset($variables['page'][$region_key])) {
$variables['page'][$region_key] = array();
}
}
将$page
描述为:
区域:
:动态帮助文本,主要用于管理员页面$page['help']
:突出显示的内容区域的项目$page['highlighted']
:当前页面的主要内容$page['content']
:第一个侧栏的项目$page['sidebar\u first']
:第二个侧边栏的项目$page['sidebar\u second']
:标题区域的项目$page['header']
:页脚区域的项目$page['footer']
template\u preprocess\u node()
已经建议了以下模板名称
$variables['theme_hook_suggestions'][] = 'node__' . $node->type;
$variables['theme_hook_suggestions'][] = 'node__' . $node->nid;
没有必要为您的主题或自定义模块提供建议。好的,您的旁注很有意义。我删除了我的建议,因为它没有必要。对于其余部分,我应该使用页面模板而不是节点模板吗?也就是说,如果我想在特定页面上呈现schools_登录区域,我应该创建一个这样做的页面模板吗?