queryStringMerge
Creates a query string containing the specified paramters as key/value pairs merged with the existing query string of the current URL. This method can be used to create links for adding or replacing some parameters of the query string without touching the other ones.
A standard use case for this method is a combined filter and sorting menu, where one button sets a filter value in the query string and the other one defines the parameter for sorting without removing each other.
<@ queryStringMerge { options } @>
Example
A combined filter and sort menu has multiple buttons to change or add only a single parameter within an URL's query string to modify the selection of a pagelist. When clicking a filter button, the sorting parameter of the query string should stay untouched and vice versa. The queryStringMerge
method is used here to add the other paramters of the current query string to the href
attribute of each filter and sort button.
<# Filter buttons #>
<ul>
<@ foreach in filters @>
<li>
<a href="?<@ queryStringMerge { filter: @{ :filter } } @>">
@{ :filter }
</a>
</li>
<@ end @>
<ul>
<# Sort buttons #>
<ul>
<li>
<a href="?<@ queryStringMerge { sort: 'date desc' } @>">
Newest On Top
</a>
</li>
<li>
<a href="?<@ queryStringMerge { sort: 'title asc' } @>">
Title A-Z
</a>
</li>
</ul>