0

I want to have easily reusable pieces of content inside my nodes. I did something with Node Embed and Exclude Node Title.

But then I found out that Exclude Node Title is really dirty and simply makes the string itself empty, but there's still HTML, so I have <h2><a href="the-piece-of-reusable-content"></a></h2>, which sucks for design (can be hacked around with CSS) but even more for SEO: I don't want my piece of reusable content to be indexed in Google, I don't want Google to start thinking I'm playing them by having an empty <a>.

Is there a good fix for this? Or maybe there's a better way to do this, e.g. by embedding blocks inside the content?

  • You’d need to provide a template without the wrapping html – Clive Nov 29 '17 at 17:08
1

node_embed uses node_view() and drupal_render() to display a node.

With the default node.tpl.php, the title is always displayed unless the node is rendered as a "page". The "page" variable is determined in an obscure way in template_preprocess_node(), and is typically false with embedded nodes. So the title will be rendered.

  <?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); ?>

I see two ways to prevent this:

  • A custom node template for the view mode that is used by node_embed, in your theme.
  • Use a display suite layout for the given view mode. With display suite, the usual node template is ignored, and the title is just one among other visual elements to be positioned in the display. I prefer this solution, because I like display suite :)

node_embed ships with a dedicated view mode 'node_embed', which is used by default for embedded nodes. So this is the one you need to configure or target with a template.

BTW, at the time of this writing, the module page of Node embed says it is no longer supported. There is another module, Entity embed, which seems not to have this problem.

| improve this answer | |
  • Great! The display suite layout works well for me. – kqw Dec 4 '17 at 18:58

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.