2

I'm using the "taxonomy term" view.

I would like to have a search form box independent of this page, which I will place for example in my navbar, allowing me to search among the terms of taxonomy, with autocompletion, and thus leading to the page of the corresponding term.

For example:

I have as taxonomy terms: tag1, tag2, tag3.

I'm on my home page, I type in the search form "tag2", I arrive on the page "tag2" with all the nodes having the tag "tag2", sort according to the criteria of the view.

I tried to create a separate block with views, but I do not get results.

I also tried to add a block to the "taxonomy term" view, but that does not work either.

Do you know how to do it ?

0

The quickest way to do it is by modifying the existing Taxonomy term View. It's good practice to Duplicate/Clone that View and work on the second instance, disable the original, so you always have the original for reference if you ever need it.

What you want is to:

  1. add the Taxonomy term Filter to that View Page display, you can use the Content: Has taxonomy term Filter, choose your relevant Vocabulary and Autocomplete
  2. Expose it,
  3. then under Advanced Views options (third column) set Exposed form in block: to Yes
  4. Save the Views
  5. Go to Blocks configuration and add the newly created Block Exposed form: clone_of_taxonomy_term-page (it may be named differently for you) and add it to a Region of your choice

This Block (which is essentially a search form for Taxonomy term Views) will be visible on all pages of your website (unless you restrict the Block Visibility). You can be on your homepage, for example, and start typing a tag name, you will get the autocomplete suggestion list, and after you choose one and search for it you will be taken to the /taxonomy/term/all?tid=tagname page that will show nodes for that tag.

You can adjust the Views to get the path to read /taxonomy/term/[tid] after using that exposed search block (to get all the features of the original Taxonomy term views such as Title showing the tag name) but it requires some playing with it, maybe a different combination of Filter and Contextual filters.

0

You can achieve this in Drupal 7 and 8 using a mixture of modules such as:

Search API

This module provides a framework for easily creating searches on any entity known to Drupal, using any kind of search engine. For site administrators, it is a great alternative to other search solutions, since it already incorporates facetting support and the ability to use the Views module for displaying search results, filters, etc. Also, with the Apache Solr integration, a high-performance search engine is available for this module.

Then you can use: Search API Autocomplete to accomplish the auto complete functionality you require

The Search API Autocomplete module in action. This module provides autocomplete functionality for Search API searches.

And all of this is managed and is customizable via Views module and having a Search API Server that indexes what you want (Here are taxonomy terms for your case)

If you want to make it easier setting things up you can try Search API Pages

This module is for creating simple search pages for the Search API project, not using Views or any other modules. They can be used when a view would be unnecessarily slow or complex, or for quickly testing out functionality. They also provide search blocks for starting a search from anywhere on the site.

  • thanks, can you give me a little more details? Especially to make the link between the view "term of taxonomy" and search API? Because I installed all the modules, configured them, but I do not see how to use search API in views – Hgfdsoiu Oct 26 '18 at 18:20
  • What version of Drupal are you using? you have both tags added to your question! – Sohail Oct 26 '18 at 18:39
  • I'm trying with drupal 8, but if I can not do it I'll do it with 7 – Hgfdsoiu Oct 26 '18 at 20:01
  • one thing I do not understand: I have to search among the taxonomy terms, to find the nodes corresponding to these terms. Is it a search for terms or a search for nodes? Hm, hard to understand ... I only have to have in the autocomplete the terms of taxonomy, and not the title of the nodes. – Hgfdsoiu Oct 26 '18 at 20:51
  • It can be a search for your terms or for your nodes, you should configure your search index the way you'd like it, I suggest searching about this on Youtube and watch some tutorials – Sohail Oct 27 '18 at 11:55

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.