渲染一个 Drupal 节点 [英] Render a Drupal node

查看:26
本文介绍了渲染一个 Drupal 节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在另一个节点内显示一个节点.所以我检索第二个节点的节点 ID,我想在另一个节点内渲染/打印/...它.
但我不知道如何做到这一点.我试过 drupal_rendernode_viewprint,...但没有结果.有什么建议吗?

$nid = $node->field_linked_fiche['und'][0]['nid'];$fullFiche = node_load($nid);

编辑 - 整个模板

<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"';} ?>><强><a href="<?php print $front_page; ?>"title="<?php print t('Home'); ?>"rel="home">

<?php else:/* 当内容标题为空时使用 h1 */?><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"><?php endif;?><?php endif;?><?php if ($site_slogan): ?><div id="site-slogan"<?php if ($hide_site_slogan) { print ' class="element-invisible"';} ?>><?php 打印 $site_slogan;?>

<?php endif;?>

<!--/#name-and-slogan --><?php endif;?><?php print render($page['header']);?><?php if ($main_menu): ?><div id="main-menu" class="navigation"><?php 打印主题('links__system_main_menu', array('链接' =>$main_menu,'属性' =>大批('id' =>'主菜单链接','类' =>数组('链接','clearfix'),),'标题' =>大批('文本' =>t('主菜单'),'级别' =>'h2','类' =>数组('元素不可见'),),));?>

<!--/#main-menu --><?php endif;?><?php if ($secondary_menu): ?><div id="secondary-menu" class="navigation"><?php 打印主题('links__system_secondary_menu', array('链接' =>$secondary_menu,'属性' =>大批('id' =>'二级菜单链接','类' =>数组('链接','内联','clearfix'),),'标题' =>大批('文本' =>t('二级菜单'),'级别' =>'h2','类' =>数组('元素不可见'),),));?>

<!--/#secondary-menu --><?php endif;?></div></div><!--/.section,/#header --><?php if ($messages): ?><div id="messages"><div class="section clearfix"><?php 打印 $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 打印渲染($title_prefix);?><?php if ($title): ?><h1 class="title" id="page-title"><?php 打印 $title;?><?php endif;?><?php 打印渲染($title_suffix);?><?php if ($tabs): ?><div class="tabs"><?php 打印渲染($tabs);?>

<?php endif;?><?php print render($page['help']);?><?php if ($action_links): ?><ul class="action-links"><?php 打印渲染($action_links);?><?php endif;?>//在这个节点中渲染第二个节点<?php$nid = 739;//注意 :: 硬编码,但需要可变!!drupal_render(node_view(node_load($nid)))?><?php print render($page['content']);?><?php 打印 $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']);?>

<!--/#footer --><?php endif;?></div></div><!--/.section,/#footer-wrapper --></div></div><!--/#page,/#page-wrapper -->

解决方案

<小时>

注意:重新发布,因为原始答案已被删除.

I would like to show a node inside another node. So I retrieve the node id of the second node and I would like to render/print/... it inside another node.
But I'm not sure how to do this. I've tried drupal_render, node_view, print,... but with no results. Any advice?

$nid = $node->field_linked_fiche['und'][0]['nid'];
$fullFiche = node_load($nid);

EDIT - the whole template

<?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 -->

解决方案

<?php
  $nid = 739; // NOTE :: Hard coded, but need to be variable!!
  print drupal_render(node_view(node_load($nid)));
?>


NOTE: Reposted, as original answer got deleted.

这篇关于渲染一个 Drupal 节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
其他开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆