I am trying to create a link in a Drupal views-view-fields.tpl that links to the original content but for some reason it's not working. The code I have tried:

<a href="<?php $fields['path']->content; ?>">Read more</a>        


<?php $link = $fields['path']->content;?>
 <a href="<?php $link ?>"> Read more</a>

as well as adding single quotes. The above points the rendered link to the current page/ view. When I echo $link_path i get /?q=node/1544 , which is correct.

I have also tried to create the URL by using

$link = $GLOBALS['base_url'] . '/node/' . $node->nid;
<a href="<?php $link ?>"> more </a>

The above shows the correct link when I echo it but, again in the rendered link it points to the current page/ drupal view.

What am I missing? I have to add that I only have about 3 months Drupal/PHP experience so still lots to learn.

Thanks :)

  • 1
    And there's another site compromised by a security problem. You really shouldn't be outputting links like that, but use l(), or otherwise rely on Drupals/Views built in functionality to generate links.
    – Letharion
    Nov 7, 2014 at 8:40

1 Answer 1


The secure alternative would be to use l() to generate the link. In your current code, it's very likely that you've created a security problem.

l('More', $fields['path']->content) would be better.

But in answer to your original question. you are missing echo statement here

<a href="<?php echo $link ?>"> more </a>
  • Thank you. I noticed the missing echo after I posted this. It doesn't work with my first example, however, as it renders /?q=node/1545"> and that link points to but I never tried the 2nd one with the echo and that seemed to have worked. Thanks so much :)
    – Christo
    Nov 7, 2014 at 8:07
  • 1
    Initially I voted down on the solution because it encourages unsafe code. I changed my mind and edited in the safer option at the top instead.
    – Letharion
    Nov 7, 2014 at 8:46
  • I tried <?php print l('More', $fields['path']->content); ?> but the link it returns is… -- what am I doing wrong?
    – Christo
    Nov 8, 2014 at 5:27
  • Ok, so for some reason I just can't get it to work if I use fields['path']->content); to generate the link even though the output of just that line seems correct. I managed to do it by using echo l('More', 'node/'.$nid); Is this fine or are there also security issues with this? THanks.
    – Christo
    Nov 8, 2014 at 14:30

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.