# controller\_template

Source: https://zotonic.com/docs/1537/controller_template

URI: https://zotonic.com/id/1537

Language: en



Show a template.

This controller renders the template configured in the dispatch rules.

Example dispatch rule:

```erlang
{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:

| Argument | Description                                                                      | Example URL   |
| -------- | -------------------------------------------------------------------------------- | ------------- |
| `id`     | A 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:

| Option         | Description                                                                      | Example                                                  |
| -------------- | -------------------------------------------------------------------------------- | -------------------------------------------------------- |
| `template`     | Name of the template to be rendered. Can also be a tuple of the following form: `{cat, Name}`. See also: <a href="/id/doc_template_tag_tag_catinclude" class="doc-reference doc-reference-tag"><code>tag#catinclude</code></a>. | `{template, "home.tpl"}` `{template, {cat, "home.tpl"}}` |
| `anonymous`    | Render the template always as the anonymous user, even when a user is logged on. Defaults to false. | `{anonymous, true}`                                      |
| `content_type` | The content type provided by the dispatch rule. Defaults to `"text/html"`.       | `{content_type, "application/json"}`                     |
| `max_age`      | The 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_action`   | What 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}`                                     |
| `acl`          | Extra authorization checks to be performed.                                      | See [ACL options](#acl-options).                         |
| `id`           | Id or unique name of a resource to be referenced in the rendered template. This overrules an id from the query arguments. | `{id, page_about}`                                       |
| `seo_noindex`  | Ask crawlers to not index this page.                                             | `seo_noindex`                                            |
| `nocache`      | Prevent browser caching this page.                                               | `nocache`                                                |
| `http_status`  | The HTTP status code to return. This defaults to `200`.                          | `{http_status, 418}`                                     |

ACL options
-----------

[Authorization](/id/doc_developerguide_access_control#guide-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 option             | Description                                                                      | Example                                       |
| ---------------------- | -------------------------------------------------------------------------------- | --------------------------------------------- |
| `is_auth`              | Disable anonymous access to this resource.                                       | `{acl, is_auth}`                              |
| `logoff`               | Log 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}]}` |
| `ignore`               | Don’t perform any access control checks. Be careful to add your own checks in the rendered template and all its included templates. | `{acl, ignore}`                               |

License: 

Attribution: 

Related resources: https://zotonic.com/api/agent/related/1537?language=en


## API access

- [API help](<https://zotonic.com/api-help>)
- [OpenAPI specification](<https://zotonic.com/openapi.json>)
- [This resource as JSON](<https://zotonic.com/api/agent/resource/1537?language=en>)
