2

I have a view that outputs rendered nodes. Setting "Show: Rendered Entity" doesn't work, because I need to add other things like edit links and custom text. So I set "Show: Fields" and used a "Rendered Node" field to output the node contents alongside everything else I needed.

The problem is that Views brilliantly wraps the entire node contents in <a></a> tags and links it to the node's page! This would be fine if I were just showing the titles, but I'm showing the node's entire rendered contents, with all sorts of <div>s and other links that need to work and other things.

Is there a way to make it not do that? There's no option for it in the field settings and I can't find where in the Views module this field is implemented.

Alternately, is there another way I can show a list of rendered nodes alongside other fields without them being stupidly linked in unconfigurable ways?

0

This happens because whenever Drupal renders a node someplace other than the node's page (for example, /node/12345) it will include the title as a link to the node itself. This is done in modules/node/node.tpl.php:

<?php if (!$page): ?>
  <h2<?php print $title_attributes; ?>>
  <a href="<?php print $node_url; ?>">
  <?php print $title; ?></a></h2>
<?php endif; ?>

To stop this from happening in your view when using the rendered node as a field, you probably want to tweak the view field template. If you override node.tpl.php in your theme, other displays of nodes (for example, the default front page) will stop working as you expect.

I did this in views-view-field--test--rendered-entity.tpl.php using preg_replace:

$output = preg_replace('@(<header class="node-header">\s+<h1 class="node-title"[^>]*>\s+)<a[^>]*>([^<>]*)</a>(\s+</h1>\s+</header>)@', '$1$2$3', $output);
print $output;

Note that the exact regex will depend on the theme you're using. This is for an Omega subtheme.

  • I forgot all about this question! I discovered a better solution a long time ago; I've added it above. Thanks for the reminder! – 75th Trombone Mar 8 '13 at 18:53
0

Turns out there is an option for it in the field settings, but there's a bug in the user interface. If you have Display set to "Show complete entity", the only sub option that appears is View Mode. However, if you set Display to either of the other options, a new checkbox appears: Link to entity. This option applies to all three Display options, not just the two on which it appears. Turn off the checkbox and set Display back to "Show complete entity", and you're done.

  • I don't think this works anymore… The image described the location perfectly, but it looks like the checkbox is no longer effective if the "Show complete entity" option is selected. I had to override the node.tpl.php file to remove the link. – thirdender Jun 26 '13 at 3:11

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.