param($key = null, $default = null)

Fetches a Kirby URL parameter

  • $key (string)
    null returns an array of all values
  • $default (mixed)
    Default value if empty
  • return (string)

Additional to URL query variables you can set parameters via URL in Kirby in a more human readable way:

http://yourdomain.com/blog/tag:mytag/year:2014

Note that you have to use a semicolon instead of a colon on Windows systems. In your code, you can use the url::paramsToString() method to make sure that the resulting URL is compatible with both Linux and Windows servers.

Those parameters are very handy when you want to build URL-based filters for your content.

Such parameters will be ignored by the router so the URL which will be fetched by Kirby in this case is http://yourdomain.com/blog

The parameters can be fetched in templates, snippets or controllers like this:

$tag  = param('tag');
$year = param('year');

You can even define a default value when a parameter is not set:

$tag  = param('tag', 'design');
$year = param('year', 2014);

Is something missing or incorrect? Edit this page on Github…