1

I have a view that shows all the contents of my site, with an exposed filter, that allows to filter these contents according to different taxonomy terms.

I would like the taxonomy term chosen via the exposed filter to appear as a page title.

Example:

  1. I type in my search form: drupal,
  2. I arrive on a page with the title "drupal" and presenting all the contents having for term "drupal".

I tried different options, especially with the contextual filter, but without success.

For example, i tried this solution (1) or this solution (2), but either I do not get any title (1), or I get many errors that make the site crash (2), of type

Warning : Illegal string offset 'value' dans Drupal\views\Plugin\views\area\Text->preQuery() ((...)/core/modules/views/src/Plugin/views/area/Text.php ligne 50)

Help would be much appreciated

Edit:

My views configuration (maybe views can't find the id in the url? The url of my page: : mysite/myviews?tid=term+taxonomy+(ID) )

enter image description here enter image description here

  • Are you entering the {{ arguments.name }} or what ever token is in your case from the Replacement patterns? It's not the same token as in D7. – prkos Feb 16 at 3:08
  • Yes, that's why I do not understand where the problem comes from! – Hgfdsoiu Feb 16 at 20:57
  • Your question is confusing, are you trying to set the title for Exposed filter or Contextual filter? Can you also update your question with your Views configuration (all the relevant ones). – prkos Feb 17 at 13:38
  • I try to set the title for page. I added my views configuration to my question – Hgfdsoiu Feb 17 at 21:18
  • It seems like it should work, if you're entering term ID numbers into the Preview/URL. Have you tried that? Term name and term ID aren't the same data, you need a Relationship towards the term database table to be able to use term names in the Views. – prkos Feb 17 at 22:09
0

To use term names in a Contextual filter in Content views you need to add the Relationship to the taxonomy reference field you have in your content. Then you'll be able to add Taxonomy term: Name Contextual filter that will take names as arguments, and not term ID numbers.

You will be able to override the title for the Name contextual the same way, only use the corresponding token for the taxonomy name. You can look it up under Replacement patterns.

You can find more details about how to set up the Name contextual here in a section of this answer: Create view with path relative to taxonomy term

  • Thanks prkos, but it does not work. I get "all" as the title. I think the problem comes from the fact of the exposed filter. As I explain in my first message, I need the title of the page to be the taxonomy term typed in the form. Ex : I type "term 1", I see the contents having "term 1", and the title of the page is "Term 1". – Hgfdsoiu Feb 18 at 14:36
  • Contextual filters and Exposed filters aren't the same thing! Add the replacement pattern to your Views Title and it will react to the Exposed filter. – prkos Feb 18 at 15:35
  • except error on my part, it does not work either ... Nothing is displayed – Hgfdsoiu Feb 18 at 15:51
  • good finally! With argument.tid and not argumet.name in title, it works! thanks prkos for your help – Hgfdsoiu Feb 18 at 21:35

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.