How do I display the search term after I have run the search.

Here is my form:

<input data-drupal-selector="edit-search-api-fulltext" id="edit-search-api-fulltext"  placeholder="Keyword" name="search_api_fulltext" value="{{ content.search_api_fulltext }}" class="regular-input" type="text">
<input data-drupal-selector="edit-submit-search" id="edit-submit-search" placeholder="Search" value="Search" class="btn secondary-btn js-form-submit form-submit" type="submit">

The value is not displaying anything, but I can't find an answer to what I should place here. Before installing Search Api I used {{ content.search_query }} and that displayed the search term after the search was performed using the out-of-the-box Drupal search.

  • 1
    "Search" and "Search API" are different modules. You'd have to check and see what template variables are available to use.
    – Kevin
    May 13, 2021 at 14:52
  • Yes, I know. That's why I explained what worked for me using search as an example of what i'm trying to do and said that I can't get it to work with Search API. I can't find anything that tells me what template variables I can use.
    – MrFox
    May 13, 2021 at 15:05

1 Answer 1


I'm using Drupal 9, and I had to create a variable in the theme and use it in my custom form template

In mytheme.theme

function hook_theme_preprocess(&$variables, $hook) {
  $variables['search_term'] = \Drupal::request()->query->get('search');

In my customtemplate.twig

<input value="{{ search_term }}" >

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.