Go to page content

Anatomy of a dispatch rule

Dispatch rules map URLs to resources and vice versa.

A dispatch rule is a pattern that is matched against the path of an incoming request URL. They are also used for the reverse action of generating request URLs in Zotonic.

A single dispatch rule looks like:

{page, ["page", id], resource_page, [{some_option,true}]}

Where the elements are:

  • a non-unique name identifying the dispatch rule (used by {% url %})
  • the path matching the request URL's path
  • the name of the resource module
  • property list with optional arguments to the resource module

URL match pattern

Every element in the URL pattern list matches to a “directory level” in the request URL. In the example, the pattern will match a URL like "page/1234" but not “pages/1234” and also not “page/1234/x”.

The possible path elements are:

  • Strings: fixed parts that must match with the request url
  • atoms: bind to the text at that position
  • '*': a special atom binding to the remaining part of the request URL, this must be the last element of the path

This page is part of the Zotonic documentation, which is licensed under the Apache License 2.0.