1

I have a view of taxonomy terms that displays Fields, including Taxonomy term: name and Taxonomy term: Term ID.

I am attempting to use a views template to customize the output of this view.

In the Views UI, if I click Taxonomy term: name, I can get an option to Link this field to its taxonomy term page.

I would like to use the link generated by this option in my views template output.

However, when I dpm($row), only the term name and term ID are returned. How does Views create the link to the taxonomy term, and how can I mimic this in my template file?

taxonomy term dpm output

1 Answer 1

2

One easy-ish way to do that within the Views UI is with the option:

"Rewrite the output of this field"

  1. Add term id field Check "Exclude from display"
  2. Order the field so it's above the other fields
  3. Edit the field you want to convert into a link
  4. Check "Rewrite the output of this field"

e.g

<a href="/taxonomy/term/[tid]">[name]</a>

to create a link.

You can also add a global "Custom text" to add arbitrary text using the replacement tokens there as well.

In that way, tokens from your view fields can be made available as replacement pattern options in your View.

2
  • When I use Link the field to its taxonomy term, Views returns the link with the pathauto alias, not the taxonomy/term/[tid] link. I was hoping to be able to grab that link instead, but if not your solution is a good compromise. Jun 27, 2013 at 4:04
  • 1
    @PatrickKenny for the alias, you may be able to add the excluded field "Path: The aliased path to this content." and use that in the replacement text href instead. Jun 27, 2013 at 4:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.