Home > widget-integration > FilterUrlHelper > setShortenedParam
FilterUrlHelper.setShortenedParam() method
Sets a shortened parameter in URL with combined values.
Used for URL scheme 2 to combine multiple values with the configured separator. Override this method to customize how shortened parameters are encoded in URLs.
Signature:
protected setShortenedParam(url: URL, key: string, rawValues: string[]): void;
Parameters
|
Parameter |
Type |
Description |
|---|---|---|
|
url |
URL |
URL object to modify in place |
|
key |
string |
The shortened parameter key (e.g., 'b' for 'pf_brand') |
|
rawValues |
string[] |
Array of values to combine with separator |
Returns:
void
Remarks
This method manually constructs the URL search string to maintain precise control over parameter ordering and encoding. It: 1. Encodes values and replaces %20 with + for compatibility 2. Combines values with the configured separator 3. Maintains sorted parameter order for consistent URLs
Example
Custom encoding for special characters:
protected setShortenedParam(url: URL, key: string, rawValues: string[]): void {
// Use custom encoding for values with special characters
const separator = this.getMultipleValueSeparator();
const encodedValues = rawValues
.map(v => this.customEncode(v))
.join(separator);
const prefix = url.search.startsWith('?') ? url.search.slice(1) : '';
const pairs = prefix ? prefix.split('&') : [];
const filtered = pairs.filter(p => !p.startsWith(encodeURIComponent(key) + '='));
url.search = [...filtered, `${encodeURIComponent(key)}=${encodedValues}`].join('&');
}