0

I've got what seem to be random empty <h3>s appearing whilst displaying a custom content type as a teaser in a pretty standard blocks display through Views. Now this is only a problem because it's adding dimension and padding, which can be aleviated but I'd actually rather like to get to the bottom of why it is happening.

<article class="node-3099 node node-feature node-teaser contextual-links-region 
        node-by-viewer clearfix" typeof="sioc:Item foaf:Document" 
        about="/feature/simplifying-copyright-through-digital-technology">
    <header>
        <h3></h3>
        <h1 class="node__title node-title">

        ...

We've created a subtheme of Zen and only have the following files overriden:

  • block.tpl.php
  • node.tpl.php
  • node--news_story.tpl.php
  • node--product.tpl.php
  • page.tpl.php
  • views-view--page.tpl.php
  • views-view-unformatted.tpl.php

I've cleared the views cache, cleared all caches, not got "compress JS/CSS" etc. selected, rescanned the template files but it makes no difference.

I've not added any custom classes to the views display settings, I've not done anything funky in the custom content types either, not the default/teaser displays. Nearly everything is as it is by default. And we're not using grouping, which I've read can be a problem.

In our custom "news_story" template (and the product one too) we'd carried over something in the header from an old build. This was displaying an empty h3 but commenting it out fixed it completely. And it was not in the rendered HTML at all. Unlike the other blocks, like the Features section.

  <?php if ($title_prefix || $title_suffix || $display_submitted || $unpublished || !$page || $title): ?>
    <header>

        <?php //DONT DO THIS WITH THE H3: it injects it even if the field_news_category is ignored?>

      <!-- <h3><?php
        // Only one of these will be shown (Domain Fields...) 
        //print render($content['field_subtype']);
        print render($content['field_news_category']);
      ?></h3>-->
      <?php
        //hide($content['field_subtype']);
       //hide($content['field_field_news_category']);
      ?>
      <?php print render($title_prefix); ?>

However, we've not overriden the other custom content types and I can't find anything in any of the other templates that has any h3 or anything. I've looked through Zen and there's nothing there. I've looked through the Views module and in the Theme folder there was a h3 in "unformatted" so I overwrote that and commented out the <h3> ...

<?php

/**
 * @file
 * Default simple view template to display a list of rows.
 *
 * @ingroup views_templates
 */
?>
<?php if (!empty($title)): ?>
  <!-- <h3><?php print $title; ?></h3> -->
<?php endif; ?>
<?php foreach ($rows as $id => $row): ?>
  <div<?php if ($classes_array[$id]) { print ' class="' . $classes_array[$id] .'"';  } ?>>
    <?php print $row; ?>
  </div>
<?php endforeach; ?>

And since we're using the "unformatted" format I can only presume that's all that's needed. I also tried commented out the <h3> in the views-view-unformatted.tpl.php file in the Views module's Theme directory. And clearing Views caches with Drush. But somehow there's still a h3 getting in there...

1
  • 1
    My first step in these situations is usually to verify that the template I think is rendering is the right one. If you enable theme_debug, you will get comments in your output to show you which template is responsible for each section of the markup. Apr 21, 2016 at 17:15

1 Answer 1

1

<h3> in the views-view-unformatted.tpl.php is outputted only if you use Grouping setting in your view. So commenting that out is a bad idea.

Looking at your markup I can say with confidence that h3 is produced by either one of the following templates:

  • node.tpl.php
  • node--news_story.tpl.php
  • node--product.tpl.php

Good point was made by rhuffstedtler, about checking which template is producing the markup.

find settings.php file and uncomment the line (usually last line) that says:

$conf['theme_debug'] = TRUE;.

Then refresh your page and check the source HTML code. You'll figure out from there which template you should be modifying.

1
  • Lesson=theme debug. Another team member copied news story and product template files for other content types and commited them, I didn't refresh Eclipse and didn't see them until the debug. Idk, maybe that's what it was. It's obviously a very localised problem. Thanks!
    – ja_him
    Apr 22, 2016 at 8:15

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.