Jorge Ben
Jorge Ben

Reputation: 51

Edit Drupal 7 template - node.tpl.php

using Drupal 7 how can you customize node.tpl.php to display an image before the title. I like to organize my html markup structure as:

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

On the "node.tpl.php" i do not see variable for field-name-field-graphic. Where is this being handle?

Below is 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>

Upvotes: 0

Views: 504

Answers (3)

Amit
Amit

Reputation: 342

Please go thru below code if it helps.

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

Upvotes: 3

Ardit Meti
Ardit Meti

Reputation: 581

This line print render($content); prints all your node content, so to print one specific field you go like this : print render($content['field_name_field_graphic']);

Upvotes: 0

Vivek Srivastava
Vivek Srivastava

Reputation: 569

You can find it inside the $node variable which is an object of the node having all the data.

Upvotes: 0

Related Questions