【问题标题】:Edit Drupal 7 template - node.tpl.php编辑 Drupal 7 模板 - node.tpl.php
【发布时间】:2015-10-07 22:40:46
【问题描述】:

使用 Drupal 7 如何自定义 node.tpl.php 以在标题前显示图像。 我喜欢将我的 html 标记结构组织为:

<div id="node-id" class="class">
  <div class="content">
    <div class="field-name-field-graphic"><img src="Untitled-2.png"></div>
    <h2>tilte</h2>
    <div class="field field-name-body">
      <p>body</p>
    </div>
  </div>
</div>

在“node.tpl.php”上,我没有看到字段名称字段图形的变量。这是在哪里处理的?

下面是node.tpl.php

<div id="node-<?php print $node->nid; ?>" class="<?php print $classes; ?> clearfix"<?php print $attributes; ?>>

  <?php print $user_picture; ?>

  <?php print render($title_prefix); ?>
  <?php if (!$page): ?>
    <h2<?php print $title_attributes; ?>><a href="<?php print $node_url; ?>"><?php print $title; ?></a></h2>
  <?php endif; ?>
  <?php print render($title_suffix); ?>

  <?php if ($display_submitted): ?>
    <div class="submitted">
      <?php print $submitted; ?>
    </div>
  <?php endif; ?>

  <div class="content"<?php print $content_attributes; ?>>
    <?php
      // We hide the comments and links now so that we can render them later.
      hide($content['comments']);
      hide($content['links']);
      print render($content);
    ?>
  </div>

  <?php print render($content['links']); ?>

  <?php print render($content['comments']); ?>

</div>

【问题讨论】:

    标签: drupal-7 drupal-theming


    【解决方案1】:

    如果有帮助,请通过下面的代码。

    <div id="node-<?php print $node->nid; ?>" class="<?php print $classes; ?> clearfix"<?php print $attributes; ?>>
    
      <?php print $user_picture; ?>
    
      <?php print render($title_prefix); ?>
      <?php if (!$page): ?>
       <div class="field-name-field-graphic"> <?php print render($content['field_name_field_graphic']);?> </div>
        <h2<?php print $title_attributes; ?>><a href="<?php print $node_url; ?>"><?php print $title; ?></a></h2>
      <?php endif; ?>
      <?php print render($title_suffix); ?>
    
      <?php if ($display_submitted): ?>
        <div class="submitted">
          <?php print $submitted; ?>
        </div>
      <?php endif; ?>
    
      <div class="content"<?php print $content_attributes; ?>>
        <?php
          // We hide the comments and links now so that we can render them later.
          hide($content['comments']);
          hide($content['links']);
          hide($content['field_name_field_graphic']);
          print render($content);
        ?>
      </div>
    
      <?php print render($content['links']); ?>
    
      <?php print render($content['comments']); ?>
    
    </div>
    

    【讨论】:

      【解决方案2】:

      您可以在 $node 变量中找到它,该变量是具有所有数据的节点的对象。

      【讨论】:

        【解决方案3】:

        print render($content); 这一行打印了你所有的节点内容,所以要打印一个特定的字段,你可以这样:print render($content['field_name_field_graphic']);

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多