0

I'm using this to print out a custom link format in views. I'm using it in the unformatted views tpl.php file.

<?php print l('<span class="link-spanner"> a</span>',
              $view->style_plugin->row_tokens[$id]['[path]'],
              array ('html' => TRUE)); ?>

This line calls the relevant HTML path:

$view->style_plugin->row_tokens[$id]['[path]']   

For example it might contain the value: localhost/drupal/node/31.

But when I put it in the l() function I get localhost/drupal//drupal/node/31.

Anyone know how I can stop the double print out? This is driving me mad.

  • I see two problems there, first one is with the path format. The path should start and ends without slash, for example: node/1. In your case, $view->style_plugin->row_tokens[$id]['[path]'] returns /localhost/drupal/somepath That's why you've got the additional slash. The second problem is with the path string, because it should be an internal path or external URL, such as "node/34" or http://example.com/foo – Jack-PL Jul 24 '13 at 21:14
  • Cheers that cleared up the confusion. I found another thread in the end and realised that I could just build the relative path using the Node ID. Posted the answer below. – Dominic Woodman Jul 25 '13 at 19:39
1
<?php print l('<span class="link-spanner"></span>',
'node/' . $view->result[$id]->_field_data['nid']['entity']->vid, 
array ('html' => TRUE)); ?>

Here is the final solution.

It will add the NID on the end of node/ and create the internal path "node/x". If you're using Pathauto this will still work.

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.