gettermfromqueryparameter

Type: string
Default: ''
Context: prediction

About this parameter

This parameter automatically gets the search term from the URL. The term is then used to filter recommendations in the same way as autocomplete.

The value can be either the name of a query parameter or a path template, depending on where the site keeps its search term.

Query parameter

Set the value to the name of the query parameter that holds the search term. For example, if the URL is https://www.example.com?query=house and the parameter is set to data-gettermfromqueryparameter="query", the term "house" is used.

The term is looked up in this order:

  1. #query/<term> in the hash, for example https://www.example.com/search#query/house. This form is always checked first, whatever parameter name you set.
  2. The query string, for example ?query=house.
  3. A query string in the hash, for example #?query=house.

Path template

Some sites keep the search term in the path instead of the query string, for example https://www.example.com/search/All/house/. For these sites, set the value to a template of the path, where:

  • {term} marks the path segment that holds the search term.
  • * matches any single path segment, for example a category that changes between searches.
URLValue
https://www.example.com/search/house/search/{term}
https://www.example.com/search/All/house//search/*/{term}
https://www.example.com/search/house/page/2/search/{term}/page/*

The value is treated as a template when it starts with / and contains {term}. The template must match the whole path, and a trailing slash is optional. The term is URL-decoded, so both %20 and + become spaces. Any hash in the URL, such as #result-list, is ignored.

Search result pages

When used together with data-renderstyle="searchresult" and a query parameter name, the value of the search field on the page (<input name="query">) is restored from the URL, so the field isn't empty after the page reloads. This isn't done for path templates, since there is no field name to match.

Example of using gettermfromqueryparameter

Usage examples

Query parameter

<div class="rek-prediction" data-gettermfromqueryparameter="query"></div>

Path template

<div class="rek-prediction" data-gettermfromqueryparameter="/search/*/{term}"></div>