渲染Drupal节点
我想在另一个节点中显示一个节点。因此,我检索第二个节点的节点id,并希望呈现/print/。。。它位于另一个节点内。渲染Drupal节点,drupal,drupal-7,drupal-nodes,drupal-render,Drupal,Drupal 7,Drupal Nodes,Drupal Render,我想在另一个节点中显示一个节点。因此,我检索第二个节点的节点id,并希望呈现/print/。。。它位于另一个节点内。 但我不知道该怎么做。我尝试了drupal渲染、节点视图、打印等等,。。。但是没有结果。有什么建议吗 $nid = $node->field_linked_fiche['und'][0]['nid']; $fullFiche = node_load($nid); 编辑-整个模板 <?php /** * @file * Bartik's t
但我不知道该怎么做。我尝试了drupal渲染、节点视图、打印等等,。。。但是没有结果。有什么建议吗
$nid = $node->field_linked_fiche['und'][0]['nid'];
$fullFiche = node_load($nid);
编辑-整个模板
<?php
/**
* @file
* Bartik's theme implementation to display a single Drupal page.
*
...
*/
?>
<div id="page-wrapper"><div id="page">
<div id="header" class="<?php print $secondary_menu ? 'with-secondary-menu': 'without-secondary-menu'; ?>"><div class="section clearfix">
<?php if ($logo): ?>
<a href="<?php print $front_page; ?>" title="<?php print t('Home'); ?>" rel="home" id="logo">
<img src="<?php print $logo; ?>" alt="<?php print t('Home'); ?>" />
</a>
<?php endif; ?>
<?php if ($site_name || $site_slogan): ?>
<div id="name-and-slogan"<?php if ($hide_site_name && $hide_site_slogan) { print ' class="element-invisible"'; } ?>>
<?php if ($site_name): ?>
<?php if ($title): ?>
<div id="site-name"<?php if ($hide_site_name) { print ' class="element-invisible"'; } ?>>
<strong>
<a href="<?php print $front_page; ?>" title="<?php print t('Home'); ?>" rel="home"><span><?php print $site_name; ?></span></a>
</strong>
</div>
<?php else: /* Use h1 when the content title is empty */ ?>
<h1 id="site-name"<?php if ($hide_site_name) { print ' class="element-invisible"'; } ?>>
<a href="<?php print $front_page; ?>" title="<?php print t('Home'); ?>" rel="home"><span><?php print $site_name; ?></span></a>
</h1>
<?php endif; ?>
<?php endif; ?>
<?php if ($site_slogan): ?>
<div id="site-slogan"<?php if ($hide_site_slogan) { print ' class="element-invisible"'; } ?>>
<?php print $site_slogan; ?>
</div>
<?php endif; ?>
</div> <!-- /#name-and-slogan -->
<?php endif; ?>
<?php print render($page['header']); ?>
<?php if ($main_menu): ?>
<div id="main-menu" class="navigation">
<?php print theme('links__system_main_menu', array(
'links' => $main_menu,
'attributes' => array(
'id' => 'main-menu-links',
'class' => array('links', 'clearfix'),
),
'heading' => array(
'text' => t('Main menu'),
'level' => 'h2',
'class' => array('element-invisible'),
),
)); ?>
</div> <!-- /#main-menu -->
<?php endif; ?>
<?php if ($secondary_menu): ?>
<div id="secondary-menu" class="navigation">
<?php print theme('links__system_secondary_menu', array(
'links' => $secondary_menu,
'attributes' => array(
'id' => 'secondary-menu-links',
'class' => array('links', 'inline', 'clearfix'),
),
'heading' => array(
'text' => t('Secondary menu'),
'level' => 'h2',
'class' => array('element-invisible'),
),
)); ?>
</div> <!-- /#secondary-menu -->
<?php endif; ?>
</div></div> <!-- /.section, /#header -->
<?php if ($messages): ?>
<div id="messages"><div class="section clearfix">
<?php print $messages; ?>
</div></div> <!-- /.section, /#messages -->
<?php endif; ?>
<div id="main-wrapper" class="clearfix"><div id="main" class="clearfix">
<?php if ($breadcrumb): ?>
<div id="breadcrumb"><?php print $breadcrumb; ?></div>
<?php endif; ?>
<?php if ($page['sidebar_first']): ?>
<div id="sidebar-first" class="column sidebar"><div class="section">
<?php print render($page['sidebar_first']); ?>
</div></div> <!-- /.section, /#sidebar-first -->
<?php endif; ?>
<div id="content" class="column"><div class="section">
<?php if ($page['highlighted']): ?><div id="highlighted"><?php print render($page['highlighted']); ?></div><?php endif; ?>
<a id="main-content"></a>
<?php print render($title_prefix); ?>
<?php if ($title): ?>
<h1 class="title" id="page-title">
<?php print $title; ?>
</h1>
<?php endif; ?>
<?php print render($title_suffix); ?>
<?php if ($tabs): ?>
<div class="tabs">
<?php print render($tabs); ?>
</div>
<?php endif; ?>
<?php print render($page['help']); ?>
<?php if ($action_links): ?>
<ul class="action-links">
<?php print render($action_links); ?>
</ul>
<?php endif; ?>
// Render second node inside this one
<?php
$nid = 739; // NOTE :: Hard coded, but need to be variable!!
drupal_render(node_view(node_load($nid)))
?>
<?php print render($page['content']); ?>
<?php print $feed_icons; ?>
</div></div> <!-- /.section, /#content -->
<?php if ($page['sidebar_second']): ?>
<div id="sidebar-second" class="column sidebar"><div class="section">
<?php print render($page['sidebar_second']); ?>
</div></div> <!-- /.section, /#sidebar-second -->
<?php endif; ?>
</div></div> <!-- /#main, /#main-wrapper -->
<div id="footer-wrapper"><div class="section">
<?php if ($page['footer']): ?>
<div id="footer" class="clearfix">
<?php print render($page['footer']); ?>
</div> <!-- /#footer -->
<?php endif; ?>
</div></div> <!-- /.section, /#footer-wrapper -->
</div></div> <!-- /#page, /#page-wrapper -->
我没有测试它,但它应该可以与
drupal_render(node_view(node_load($nid)))
注意:重新发布,因为原始答案已被删除。drupal 7
我猜你做错了什么,因为我做了同样的事情(drupal\u render(node\u view(node\u load($nid)))
)在同一页面上显示多个节点,效果非常好。而你在你的页面中做到了。tpl?我很好奇你是怎么做到的。。。您刚才发布的脚本在我的页面.tpl.php
中没有任何作用。我得到了这个错误:Strict警告:include()中只有变量应该通过引用传递(第9行***
可能是版本不匹配?在Drupal 6中,node\u view()
返回主题节点(即,它在内部调用Drupal\u render()
),因此它给出了已经呈现的和“准备使用”的标记。在Drupal 7中,node\u view()
只准备drupal_render()生成标记所需的结构化数组。+1删除不需要的负数(可能不值得再次麻烦主持人重新删除;)我没有测试它,但它应该与drupal_render(节点视图(节点加载($nid))一起工作)不,我告诉过你我已经试过了……我猜你做错了什么,因为我做了同样的事情(drupal\u渲染(node\u视图(node\u load($nid)))
)在同一页面上显示多个节点,效果非常好。我在一个模块中完成了这项工作,不是在page.tpl.php中,但语法应该是相同的。此外,我首先加载节点,然后进行渲染:$node2=node\u load\u multiple($nids);
$output=drupal\u render(node\u view($node2));
您忘记打印渲染内容:)在重新发布时添加注释,以防止版主混淆;)最好使用变量来避免严格警告这将导致严格警告:只有变量应该通过引用传递。
<?php
$nid = 739; // NOTE :: Hard coded, but need to be variable!!
print drupal_render(node_view(node_load($nid)));
?>
<?php //use variable to avoid strict warning
$nid = 739;
$nodeview = node_view(node_load($nid));
print drupal_render($nodeview);
?>