2

I would like to know if there is a way to wrap the nodes teaser in a without using jQuery.

Basically, this is how the DOM is :

<div id="block-system-main" class="block block-system"> <!-- printed by the page.tpl.php -->
    <div class="term-listing-heading">
        term description, others custom fields…
    </div>
    <div class="node-teaser">teaser content</div>
    <div class="node-teaser">teaser content</div>
    <div class="node-teaser">teaser content</div>
<div>

What I want :

<div id="block-system-main" class="block block-system"> <!-- printed by the page.tpl.php -->
    <div class="term-listing-heading">
      term description, others custom fields…
    </div>
    <div class="wrap"> <!-- put a wrapper here -->
        <div class="node-teaser">teaser content</div>
        <div class="node-teaser">teaser content</div>
        <div class="node-teaser">teaser content</div>
    </div>
</div>

I'm using Display Suite for a better customization, I checked all the tpl files, but I found nothing…

Thx :)

2
  • this might be helpful: drupal.org/node/1869632
    – Geoff
    Apr 2, 2015 at 13:32
  • Thank you :) But it explain how to theme the inside of the node teaser (which is already very simple with Display Suite), not how to theme the wrapper of ALL the nodes teaser.
    – elkz
    Apr 2, 2015 at 13:56

2 Answers 2

2

Using template.php and hook_preprocess_page()

function THEMENAME_preprocess_page(&$variables) {
  if (arg(0) == 'taxonomy' && arg(1) == 'term' && is_numeric(arg(2))) {
    $variables['page']['content']['system_main']['nodes']['#prefix'] = '<div class="here-is-your-div">';
    $variables['page']['content']['system_main']['nodes']['#suffix'] = '</div>';
  }
}

So what this does is checks if the URLs match the condition /taxonomy/term/%term-id then if it's satisfied then it adds a prefix and a suffix that are to be rendered by <?php print render($page['content']); ?>.

4
  • Ah… I didn't know we could do that… interesting! But it's wrapping the content, and the taxonomy term description and the nodes teaser are already in it. It's not wrapping all the nodes teaser. :s
    – elkz
    Apr 2, 2015 at 14:04
  • Oh! I'm really sorry! I forgot that detail. I've updated my post already. :) Apr 2, 2015 at 15:25
  • You're very welcome! Glad to help! :) Apr 3, 2015 at 2:35
  • This prevented me from tearing out my hair in frustration.
    – oranges13
    May 26, 2016 at 19:20
0

Like many other things in Drupal, why this isn't something that was accounted for is beyond me. Here's an alternative approach that seems a little cleaner to me than the accepted answer. I don't like messing with prefixes/suffixes, and it bothers me when I can't access a template directly.

Add some additional template suggestions to nodes based on view mode:

THEME_preprocess_node(&$vars) {
  $view_mode = $vars['view_mode'];
  $vars['theme_hook_suggestions'][] = 'node__' . $view_mode;
}

Then you can have templates for 'node--full.tpl.php', 'node--teaser.tpl.php', etc., like it should probably do by default.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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