0

Hello i am struggling here a bit to change the display of my node teasers. I was hoping to take the title and submitted part and put it on top of my body field to the right of my teaser image. Ive tried Panelizer (looks great but the image field stays there if there is an image or not), Entity View Modes (dont know if this is really what i need) and even tried what could be the best way just simply editting the node.tpl and changing the fields about.

I think i'll just go with the last way as i did almost have it but due to a lack of knowledge and trouble finding out more ive had to ask you guys for some help.

I think i need to add

    <?php if ($teaser): ?>
        something in here
        <?php endif; ?>

but either it just not working (soz ive been up 24hs and im at the end of the line i think. Just hoping for some help either before bed or for when i get up) or else i get 2 body texts and titles appearing. I was just wanting my image on the left then to the right my title nd submitted fields above the body text.

I hate folks that do this but im gonna give it a go as im too tired to think now im sorry. here is my node.tpl Even just a good suggestion of what to do would be great. even better would be reworked code and i wont learn anything at all but i have tried. Tried for the past 4 hours

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

      <?php if ($title_prefix || $title_suffix || $display_submitted || $unpublished ||   !$page && $title): ?>
        <header>
          <?php print render($title_prefix); ?>
          <?php if (!$page && $title): ?>
            <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): ?>
            <p class="submitted">
              <?php print $user_picture; ?>
              <?php print $submitted; ?>
            </p>
          <?php endif; ?>

          <?php if ($unpublished): ?>
            <p class="unpublished"><?php print t('Unpublished'); ?></p>
          <?php endif; ?>
        </header>
      <?php endif; ?>

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

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

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

    </article><!-- /.node -->

Thanks in advanced. Ive got to the stage where even posting code on stackexchange is hard work for me :(

18
  • My main problem before was duplicate titles and node bodies Or none at all on the node itself. As i say i went down other avenues with other modules and im back to the start where maybe i should be. thanks
    – Reg Gordon
    Commented May 7, 2013 at 13:38
  • You could try a simple debug to establish which view mode your in or rather if your actually using a teaser view mode by giving the $teaser variable a var_dump($teaser). For view mode use the $view_mode variable.
    – Alex Gill
    Commented May 7, 2013 at 13:49
  • im just in normal teaser view mode Alex. ive created a few other view modes but i think just simply editting the node tpl would work best for me. My main problem seems to be just putting the node.tpl back together proper. Ive had 2 bodies and no bodies etc so what im doing is defo effecting the teaser. I remeber back to D6 and i used to see the teaser and the full node all on one tpl and i think im almost 'good enough' lol to go this road. I just dont know the simple basics of variables etc to do it though although i have tried.
    – Reg Gordon
    Commented May 7, 2013 at 13:59
  • I dont want to add anything nor take anything away i just want to have my title and submitted fields to the right of the teaser image instead of on top of it. Thanks
    – Reg Gordon
    Commented May 7, 2013 at 14:00
  • ps im sorry if i misunderstood your reply. I am tired.Maybe i should sleep and start afresh tomorrow.
    – Reg Gordon
    Commented May 7, 2013 at 14:04

2 Answers 2

1

Example

<?php if ($teaser): ?>
    <?php print render($content['YOUR_IMAGE_FIELD']); ?>
    <?php print render($title_prefix); ?>
        <?php if ($title): ?>
          <h2><?php print $title; ?></h2>
        <?php endif; ?>
    <?php print render($title_suffix); ?>
    <?php hide($content['YOUR_IMAGE_FIELD']); ?>
    <?php hide($content['links']); ?>
    <?php print render($content); ?>
    <?php print render($content['links']); ?>
<?php else: ?>
   //...show default view mode
<?php endif; ?>

Most of the fields are bundled together into the $content variable.

We can remove them from being output in the $content variable by using the hide() function just before we render it (see above).

We can then print the specific field anywhere we like in the template like. See above where weve put the image field.

To determine what fields you have to play with do a var_dump($content) at the top of the template or even better use the Devel module to do this.

17
  • ah brilliant alex thanks. Let me go try. i would say brb but that might not be the case lol
    – Reg Gordon
    Commented May 7, 2013 at 15:59
  • Haha no worries, let us know how you got on!
    – Alex Gill
    Commented May 7, 2013 at 16:01
  • after the first else should i start from.. <?php if ($title_prefix || $title_suffix || $display_submitted || $unpublished || !$page && $title): ?>
    – Reg Gordon
    Commented May 7, 2013 at 16:04
  • i see what your saying now and have been trying to say from the start. I need to know my specific fields. let me go try but again im still worried about where the rest of the template i posted goes after you code...
    – Reg Gordon
    Commented May 7, 2013 at 16:05
  • You want to put everything in your example from <?php if ($title_prefix to $content['comments']); ?> in the else statement.
    – Alex Gill
    Commented May 7, 2013 at 16:08
0

updated node.tpl

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

    <?php if ($teaser): ?>
        <?php print render($content['field_imageown']); ?>
        <?php print render($title_prefix); ?>
            <?php if ($title): ?>
              <h2><?php print $title; ?></h2>
            <?php endif; ?>
        <?php print render($title_suffix); ?>
        <?php hide($content['field_imageown']); ?>
        <?php print render($content); ?>
    <?php else: ?>

      <?php if ($title_prefix || $title_suffix || $display_submitted || $unpublished || !$page && $title): ?>
        <header>
          <?php print render($title_prefix); ?>
          <?php if (!$page && $title): ?>
            <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): ?>
            <p class="submitted">
              <?php print $user_picture; ?>
              <?php print $submitted; ?>
            </p>
          <?php endif; ?>

          <?php if ($unpublished): ?>
            <p class="unpublished"><?php print t('Unpublished'); ?></p>
          <?php endif; ?>
        </header>
      <?php endif; ?>

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

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

  <?php print render($content['comments']); ?>
<?php endif; ?>
</article><!-- /.node -->

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.