0

How do I display (or render in twig) the search term, entered in the search field. When you enter a search term and click on the search button, you will go to the search results page (view).

In the header of that view I want to display something like:

Your search of [mysearcherm] has x number of results.

I build the search field with a views exposed form and Search API.

Update: In the textarea of the views header I want to insert the search term as replacement token, but it's not available?

0

You can show the relevant search term in Text area when you add it to the Header option in Views.

When you tick the Use replacement tokens from the first row option you will see the Replacement patterns tokens available, and below that global replacement tokens.

You can use something like:

<div class="messages messages--status">Your search of {{ name }} has [view:total-rows] result(s). </div>

Although you'll probably want to take care of plurals more intelligently and also use a twig conditional to not show anything if the Exposed form isn't used.

  • ok good idea, but the token for the search term is not available..? – meez Sep 24 at 20:12
  • Can you update your question with the Exposed filter config and the Text area tokens? – prkos Sep 24 at 21:01

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.