controller_template (zotonic_mod_base v1.0.0-rc.17)

Show a template.

This controller renders the template configured in the dispatch rules.

Example dispatch rule:

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

This will render the home.tpl template at the url /.

Dispatch arguments

controller_template recognizes the following arguments inside the dispatch pattern:

ArgumentDescriptionExample URL
idA resource id to be used in the template. This can be the numerical id or the unique name of a page. More commonly the id is given as a dispatch option./page/12345

Dispatch options

The following options can be given to the dispatch rule:

OptionDescriptionExample
templateName of the template to be rendered. Can also be a tuple of the following form: \{cat, Name\}. See also: catinclude.\{template, “home.tpl”\} \{template, \{cat, “home. tpl”\}\}
anonymousRender the template always as the anonymous user, even when a user is logged on. Defaults to false.\{anonymous, true\}
content\_typeThe content type provided by the dispatch rule. Defaults to “text/html”.\{content\_type, “application/json”\}
max\_ageThe number of seconds of how long to cache this file in the browser. Sets the response header: Cache-control: public; max-age=X.\{max\_age, 3600\}
acl\_actionWhat ACL action will be checked. Defaults to ‘view’; but can also be ‘edit’ if users need edit permission on the rsc to be able to access the resource.\{acl\_action, edit\}
aclExtra authorization checks to be performed.See ACL options.
idId or unique name of a resource to be referenced in the rendered template. This overrules and id from the query arguments.\{id, page\_about\}
seo\_noindexAsk crawlers to not index this page.seo\_noindex
nocachePrevent browser caching this page.nocache
http\_statusThe HTTP status code to return. This defaults to 200.\{http\_status, 418\}

ACL options

Authorization checks to perform, in addition to the acl_action dispatch option, can be given in the acl dispatch option, and accepts the following options:

ACL optionDescriptionExample
is_authDisable anonymous access to this resource.{acl, is_auth}
logoffLog out user before processing the request.{acl, logoff}
{Action, Resource}Check if user is allowed to perform Action on Resource. The example is equivalent to the options {acl_action, edit}, {id, my_named_page}.{acl, {edit, my_named_page}}
[{Action, Resource}]A list of checks to be performed, as above.> \{acl, \[ > \{view, secret\_page\}, > \{update, 345\} > \]\}
ignoreDon’t perform any access control checks. Be careful to add your own checks in the rendered template and all its included templates.{acl, ignore}

See also

controller_page.

Summary

Functions

content_types_provided(Context)

is_authorized(Context)

process(Method, AcceptedCT, ProvidedCT, Context)

service_available(Context)