0

I'm trying to create a variable to put in a l() function. It's the $rellink below.

<?php print l('<span class="link-spanner"></span>', "$rellink", array ('html' => TRUE)); ?>

I have a list of content nodes I'm displaying in an un-formatted view. I want $rellink to be the link for each of them. So on item 1, it's the link to item 1. On item 2 it's the link to item 2 and so forth.

In the unformatted.tpl.php file I can print out

<?php print $view->style_plugin->row_tokens[$id]['[view_node]']; ?>

Which will print the correct link. But I need this inside the link part of the l() function and when I copy and past it in, it doesn't work.

So the question is, what have I done wrong there or if that's not possible/bad practice how do I set-up a variable in my preprocess function that I can use instead?

I've tried this in the preprocess funtion:

$view = $variables['view'];
$rellink = $view->style_plugin->row_tokens['$id']['[view_node]'];

But it doesn't recognise the global $id variable and I get an un-defined variable rellink variable warning anyway.

1 Answer 1

0

I accidentally left the quotes in when entering the variable path so it didn't work. I was entering:

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

And the I should've been putting in:

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

When you're calling a value in an array, it won't work if you put the path in quotes.

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.