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?

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']);
| improve this answer | |
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.

| improve this answer | |
  • Welcome to Drupal Answers. please don't add promotion links to your answers. :) – Krishna Mohan Nov 18 '14 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>.

| improve this answer | |
  • That call to the url() function is not going to work. Also, it's preferred to use the l() function to generate <a> tags. – marcvangend Jun 29 '14 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. – marcvangend Jun 29 '14 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. – marcvangend Jul 1 '14 at 6:02

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.