Go to page content

Useful dispatch rules

A list of the more useful dispatch rules.

The standard modules in Zotonic define quite a few dispatch rules. Some are interesting, others are for internal Zotonic use. Here we list some useful dispatch rules and explain their usage.


{home, [], resource_template, [ {template, "home.tpl"} ]}

Refers to the site's home page. This shows the template “home.tpl”. In Zotonic sites there is often a home article whose page path is defined as “/”. In this way the home page can be added to menus and the texts on the home page are made editable. The name of this article is normally set to “page_home”.


{page, ["page", id], resource_page, [ {template, "page.tpl"} ]},
{page, ["page", id, slug], resource_page, [ {template, "page.tpl"} ]}
The default page controller. Shows a HTML representation of a page.

The contoller checks if the page with the given id exists, and if the user has access to the page.  When the user doesn't have access then a logon page is shown.  When the user has access then the template “page.tpl” is used to show the page.

The template's only argument will be the integer id of the requested page.

When the page has slug defined then the slug is added to the url when the url is generated by using “m.rsc[id].page_url” in the template or “m_rsc:p(Id, page_url, Context)” in Erlang. The slug is not checked against the current slug, only the id of the page is of importance.


{id, ["id", id], resource_id, []}

This controller provides a short url for a page. The user is redirected to the page's normal url. This controller will check the HTTP Accept header to determine to which url the user agent will be redirected.

The redirect is done with a HTTP “303 See Other”.


{lib, ["lib",'*'], resource_lib, [ {use_cache, false} ]}

The controller serving all Javascript, CSS and other static files. In the default configuration it assumes that the requested files are located in the lib directory of a module. The path after the “lib/” part of the URL is the relative path in the lib directory.

This controller can concatenate multiple Javascript or CSS files in a single request. See the {% lib %} template tag for an example of its usage.


{image,["image",'*'], resource_file_readonly,
         [ {use_cache, false}, {is_media_preview, true} ]}

Show an image using filters and resizing. This dispatch rule is used by the {% image %} tag.


{media_inline, ["media","inline",'*'], resource_file_readonly, 
         [ {use_cache, false}, {content_disposition, inline} ]}

Show a file (medium) inline. The browser will try to display the file, and let the user download the file when it can't be displayed. The '*' should be set to the filename, for example:

{% url media_inline star=m.rsc[id].medium.filename %}


{media_attachment, ["media","attachment",'*'], resource_file_readonly, 
         [ {use_cache, false},{content_disposition, attachment} ]}

Download a file (medium). The file is sent to the browser with the explicit instruction that the file should be downloaded and not displayed. The '*' should be set to the filename, for example:

{% url media_attachment star=m.rsc[id].medium.filename %}


{api, ["api",module,method], resource_api, []}

The url for an api method. The api methods are defined in the services directory of the modules. Parameters are the module name and the name of the method to be called.


{favicon, ["favicon.ico"], resource_file_readonly, 
         [ {path, "images/favicon.ico"}, {root,[lib]},
           {use_cache, false}, {content_disposition, inline} ]}

The site's favicon. It can be overruled by either placing a file “images/favicon.ico” in the site's lib folder or by defining a favicon dispatch rule.


{robots_txt, ["robots.txt"], resource_file_readonly, 
         [ {path, "misc/robots.txt"}, {root,[lib]},
           {use_cache, false}, {content_disposition, inline} ]}

The robots.txt file defines how crawlers behave when visiting the site. The default robots.txt file allows to crawl the whole site, no exceptions. The default can be overruled by either placing a “misc/robots.txt” file in the site's lib directory or by overruling the robots_txt dispatch rule.


{admin, ["admin"], resource_admin, []}

The url of the admin's dashboard interface.


{admin_edit_rsc, ["admin", "edit", id], resource_admin_edit, []}

The url of the admin page to edit a resource (aka page). The numerical id of the page needs to be supplied.

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