0

In the comment.tpl.php I've shown the comment parent node title by:

$node->title 

I need to make this title link back to the parent node:

$node->$node_url

But this doesn't work. How should I do that?

3 Answers 3

1

You can use the entity_uri() and l() functions, similar to how it's done in template_preprocess_node():

$uri = entity_uri('node', $node);
$link = l($node->title, $uri['path'], $uri['options']);
0

Your code should almost work now, I think you missed a print right before the url().

However, it's unsafe to simply print the node title without properly escaping it with check_plain(). So that's another good reason to use the l() function.

1
  • Welcome to Drupal Answers. please don't add promotion links to your answers. :) Commented Nov 18, 2014 at 9:37
-1

You can achieve your goal with the following line of code:

<a href="<?php print url('node/'.$node->nid) ?>"><?php print $node->title; ?></a>.

3
  • That call to the url() function is not going to work. Also, it's preferred to use the l() function to generate <a> tags. Commented Jun 29, 2014 at 19:40
  • Your code should almost work now, I think you missed a print right before the url(). However, it's unsafe to simply print the node title without properly escaping it with check_plain(). So that's another good reason to use the l() function. Commented Jun 29, 2014 at 20:24
  • I'm sure it works at first sight. But guess what happens if you create a node with the title <script>alert('Hi');</script>, and think what that means for the security of your site and the people visiting it. I'm not saying you must use l(), but using it would automatically have prevented a security mistake like this one. Commented Jul 1, 2014 at 6:02

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.