|parametre_url

The |url_parameter filter adds or removes a parameter to a URL tag.

Use

This filter therefore applies to a URL tag, for example #SELF, #URL_ARTICLE, #URL_PAGE{summary}...
Typically, the tag will be placed in the href attribute of a link:

<a href="[(#SELF|parametre_url{pays,france})]">France</a>

will add to the url of the current page either :

  • ?country=france if this is the first parameter passed to this url,
  • &country=france if the url already has at least one parameter.

Passing several parameters to the URL

You can combine filters to pass a series of parameters and their values to the URL:

 [(#SELF|parametre_url{pays,france}|parametre_url{currency,euro})]

 
If we want to pass the same value to several parameters, we would use this syntax:

[(#SELF|parametre_url{country|location|land,france})]

which will return the current page’s URL suffixed with: country=France&location=France&territory=France.

Passing an array of values

If you want to pass multiple values for the same argument, you can pass the array of values, using the #ARRAY or #LISTE tags.
Example:

[(#SELF|parametre_url{ville,#LISTE{Toulouse,Valence,Montpellier,Paris}})]

Deleting existing settings

To make an existing URL parameter disappear, you need to empty it’s value by declaring a new one that is explicitly empty:

[(#SELF|parametre_url{country,''})]

 
You can delete several parameters at once by writing :

[(#SELF|parametre_url{pays|lieu|terrain,''})]

Retrieving a parameter passed in a URL

We will use the #ENV.

Thus, in the example:

<a href="[(#SELF|parametre_url{country,france})]">France</a>

#ENV{pays} will return france.

As another example, the "Calendrier_mini" plug-in retrieves information from the mini-calendar display context as follows [1]:
... #ENV{urljson}|parametre_url{id_rubrique}  ...

Explanation: the variable #ENV{urljson} contains a url and the above code returns the value of id_rubrique if this parameter is present in the url in question.

Forcing the separator

By default, URLs are encoded with the &amp; separator but it is possible to force the separator by specifying a 3rd argument
|parametre_url{variable name, value, separator}

So

[(#URL_PAGE{block}|parametre_url{id_block, 5})]

will return spip.php?page=block&amp;id_block=5

 ````spip
[(#URL_PAGEblock|url_parameterblock_id, 5, &]
```
will return spip.php?page=block&id_block=5


See also

Footnotes

[1See full code on the area: http://zone.spip.org/trac/spip-zone....

Author jack, Mark Published : Updated : 23/04/23

Translations : català, English, Español, français, Nederlands