Score:0

Display title, based on exposed filter of view

gu flag

I've read these questions:

But it did not help.

My Drupal version is 9.1.9. I have views displaying Taxonomy terms. Each taxonomy term has fields, for example "Genre". I have 16 different genres with "key|value" type.

I have exposed filter, based on genre field. I've added this field to Contextual filters and override the title, when filter value is in URL.

But!

  1. If there is no value in URL title displays "All", but it should display default view title.
  2. If filter is applied and there is value in URL, title displays field's KEY, but not it's VALUE, for example "2" (not the name of the genre).

What am I doing wrong?

Score:1
mx flag
  1. Did you enable the override title under Exceptions when the Display all results for the specified field is chosen under When the filter value is NOT available? Then it's doing what it's supposed to do, that override is only for the Exception, and you most likely have the value All there. Turn that title override off, and the default Title will be shown in the case when there is no argument for the filter.
  2. List fields only store key, not the value! That is why the Contextual is using and showing they key. If your value isn't complex maybe you can use it as the key as well? You don't need to enter both key and value into Field settings, if you enter only one it will be used as both the key and value. If you're dealing with phrases you can maybe construct the keys with "-" or "_" and keep the values properly capitalized. This will give you predictable Contextual filter arguments.
bigboy avatar
gu flag
1) Title override has no impact if I choose to "Display all results", view just shows standard title. If I choose "Provide default value" it shows "All", ignoring title override under exceptions again.
bigboy avatar
gu flag
2) In field settings is says that "There is data for this field in the database. The field settings can no longer be changed". So if I change it i will lose all data. And moreover, my main site language is not English, so there might be some path issues with filters if i remove "key|value" and replace it with just "value"?
bigboy avatar
gu flag
2) "List fields only store key, not the value!" but how is it showing correct values in filter dropdown then? If it's possible to show it on page, then it is rendered somehow, why is is so difficult to put it in title? I'm so confused...
mx flag
1) update the Q with info on where you override the title under default value (screenshot)? Validation is done below in the next section, not in the section where no argument is present. 2) Be careful with changing the field settings, I haven't tried it on a key|value field. If it's just expanding the number of values there I think you're safe even with the warning. Usually people ask about reducing the number of field values, you can search for those questions. 2) I couldn't find a way to show Value in Views Title. It's not impossible, but it may need custom coding to fix.
bigboy avatar
gu flag
Thanks for yor help! I've created new test select field with just values and it worked. Title is now showing correctly, but there is an issue with paths. For example it can be /?field_test_value=THIS+IS+FIELD+VALUE, but field value is not in english and it causes some issues, for example when pasting url somewhere else. But thisis not related to this question. So now I need to override URL for filter pages in this view.
mx flag
For multivalue fields Contextual filters provide the AND and OR operators for the case when you want to provide more than one argument at the same time, and the characters are usually `+` and `,` so be careful about using + ;)
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.