0

A view called "Music".

Fields: "title", "image" Exposed filter: "category" (is a taxonomy-field = rock, jazz, salsa,...). Every taxonomy-term has a description.

When the visitor for example, selects "rock" the results are filtered. So far, so good.

But i want also want that when a "category" is selected, the description of the selected term is displayed above the results.

I think that could be done with an attachment and contextual filters, but i can't get it working.

4
  • is this Drupal 7 or 8 ? Commented Apr 6, 2017 at 14:09
  • it is in Drupal 8
    – jimi
    Commented Apr 6, 2017 at 15:09
  • Can you not place the Term Description in the view header area? Is it an option? You may have to create a relationship to the vocabulary first.
    – Kevin
    Commented Apr 6, 2017 at 15:47
  • no, when creating a relationship, you can only load the description in the field-area, not in the header
    – jimi
    Commented Apr 6, 2017 at 15:51

1 Answer 1

1

You may use tokens (replacement patterns). If you add the term description in your fields and exclude it from display, you will have access to [description] token in a Global: Text area, for example, added in the view header. Then, if you check Use replacement tokens from the first row and set your exposed form style on Input required, when a category is selected, results will be filtered and the term description related to this category will be displayed in the header.

EDIT : for Drupal 8 (sorry, still more a "7 guy" ^^), the token follows Twig syntax : {{description_value}}

5
  • that works partially, but not all the terms have a description. Only when a description is available it should be shown. With your solution it shows always a description.
    – jimi
    Commented Apr 12, 2017 at 18:18
  • Make sure you tick "Use replacement tokens from the first row" in the global text area, if so, the view will display the tag description of the term selected in the exposed filter. If no description is available, the header should be empty (I've just tried). Tell me and I will add screenshots to my answer.
    – Toki
    Commented Apr 13, 2017 at 9:08
  • it's a strange thing: when all the values are shown (i have no input required) the description with the lowest id is shown. When i leave this empty, nothing is showed. How can i put a screenshot here?
    – jimi
    Commented Apr 13, 2017 at 16:14
  • but for the rest it's working :-)
    – jimi
    Commented Apr 13, 2017 at 16:15
  • Indeed, if you tick "Use replacement tokens from the first row" with a Basic exposed form, you will display the first row term description (depending on your sorting). That is why I suggest to use an Input Required exposed form style so the first row will be related to your user's choice from the vocabulary exposed filter. If you need to add screenshot, just edit your question and use the image tool in the wysiwyg interface. Anyway, I am glad if it helps =)
    – Toki
    Commented Apr 14, 2017 at 8:17

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.