1

I have a view that shows a field which is a taxonomy term reference set to display each term as a link. The taxonomy names are quite long so I want to rewrite them using a views template.

I made a template like this:

foreach ($row->field_field_ad_purpose as $data):
  if ($data['rendered']['#title'] == 'Apples, oranges, pears, and strawberries'):
    $data['rendered']['#title'] = 'Fruits';
  print $output;

Using dpm(), I was able to confirm that the #title is in fact shortened. However, printing $output prints out the original title. I also tried printing $data, but this just gives Array. What is the function to call to print out the term as a link?

2

You need to create another field with the 'path' and set this to not display by default within the views UI.

You can then get the 'path' variable in your template along with the 'title' variable and create your link using Drupals l() function.

   print l($data['rendered']['#title'], $path);

http://api.drupal.org/api/drupal/includes%21common.inc/function/l/7

| improve this answer | |
  • Ok, I see. Since I already set it to output a link in the views UI, though, there is no need to add another field. I did it like this: print l($data['rendered']['#title'], $data['rendered']['#href']); – Patrick Kenny May 1 '13 at 11:20
  • Ahh even better! – Alex Gill May 1 '13 at 11:29

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.