I use a view to display a list of books sorted by title. The view has a contextual filter to limit the list by topic. So, a link to the view might be /books-by-title/34 where 34 is the taxonomy term id for "self-help". The result is a list of self-help books in title order. Works great.

The user may also want to view the same books in popularity order, so I include a menu in the view header, one choice being "By Popularity". The menu link needs to be /books-by-popularity/34.

How do I pass the term id (34) from the URL into the menu link?

Seems like this should be easy, but after reading a dozen articles and trying several approaches, no success.

I should note that a given book be assigned more than one topic. For example, a "self-help" book may also be classified as being about "exercise". So I can't get the term id simply by looking at the topic field of the book.

2 Answers 2


Something about the answer by @No Sssweat got me thinking, so I searched differently and discovered that arguments.field_topic_target_id contains the value from the contextual filter. So, the answer is to my question is to use:

/books-by-popularity/{{ arguments.field_topic_target_id }}

as the Popularity link in the menu. Credit to @No Sssweat for providing the spark!


In Fields, add field_taxonomy (the field that references the tax term) and checkmark ☑ Exclude from display.

In Header, add Global: Text area (Global: Text area) and checkmark ☑ Use replacement tokens from the first row and use the proper replacement pattern.

Something like /books-by-popularity/{{ field_taxonomy }}

  • 1
    Thanks for this answer @No Sssweat! It's a good one. It would be perfect except that some books are classified under more than one topic. I've edited my explanation above to clearly state this fact (my bad). I've upvoted your answer. Still hoping someone will say, "Yeah, there's this variable X that contains the value from the contextual filter. You just use that." Mar 27, 2019 at 4:23

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.