site

Retrieve information that is stored in the site configuration. If you want to query values from the config table instead, you should use m_config.

Note

In general the site configurarion is only accessible via the m.site template model for users with administrator rights. Exceptions are keys starting with public or {{ m.site.title }}, hostname configurations and the paglen.

Fetch a site configuration key

Example, fetching the site configuration key "hostname":

{{ m.site.hostname }}

Fetching all configurations

It is easy to loop over all site configurations:

{% for key, value in m.site %}
  {{ key }} -- {{ value }} <br>
{% endfor %}

Overriding config values

Zotonic has two places where a site's configuration is kept. One is in the site's config files, the other in the config table. The config table (accessible through m_config) overrules any module settings from the config file, for rows where the module key of the config value is set to site.

Within the site configuration, you can override module-specific configuration: Module configurations are defined with a property key equal to the module name, with a property list as value. For example:

{mod_foo, [ {hostname, "localhost"} ]}

will put the default "hostname" setting of the imaginary mod_foo module to localhost.

Default config values

Sites have the following default config settings:

PropertyDescriptionExample value
environmentSet the DTAP status of the site. Can be one of production, development, test, acceptance, education or backup. Default: productiondevelopment
hostnameThe hostname of the siteexample.com
titleThe title of the site."My Awesome Blog"
protocolThe main protocol of the site. Used to construct urls. Default "http"."https"
document_domainThe document domain used for cross domain iframe javascripts. Default is the same as the cookie_domain.www.example.com
cookie_domainThe domain to use on cookies. This defaults to undefined, which will equal the domain of the current request..example.com
session_expire_inactiveUser inactivity timeout after seeing that the user has not been active. Default: 14400 (4 hours)3600 (1 hour)
autologon_expireAuto logon cookie timeout setting. Default: 15552000 (3 months)31536000 (365 days)
siteThe name of the site, an atom.wwwzotonic.
hstsIndicate if the site should use Strict Transport Security. When set, the browser will no longer use insecure http to access the site. Warning: Be sure your site is accessible via https before enabeling this feature. Default: falsetrue
hsts_maxageThe time, in seconds which browsers are allowed to remember the HSTS setting of the site. Default: 17280000 (200 days)
hsts_include_subdomainsWhen set, the browser also does not use http for subdomains. Default: false
hsts_preloadWhen set, the site's HSTS setting will be stored by the browser vender. This means that browsers only use https. Use with care, because it is hard to revert wrong settings. Default: false

Available Model API Paths

MethodPath patternDescription
get/site/...Return the current site name (atom) from the request context.
get/environment/...Return the resolved DTAP environment (development, test, acceptance, production, education, or backup).
get/hostname/...Return the configured hostname for the current site/request.
get/hostname_port/...Return hostname including configured HTTP port.
get/hostname_ssl_port/...Return hostname including configured HTTPS port.
get/hostalias/...Return the configured hostalias site setting.
get/protocol/...Return the site protocol used for URL construction (typically http or https).
get/is_ssl/...Return whether the site is currently considered SSL-enabled.
get/title/...Return the configured site title as binary text.
get/subtitle/...Return the configured site subtitle as binary text (empty binary when unset).
get/email_from/...Return the effective sender address used for outgoing email.
get/pagelen/...Return default search page length (configured value or fallback default).
get/language/...Return the current request language.
get/default_language/...Return the site default language.
get/security/...Return generated security.txt data (contact, optional policy/hiring, and expires).
get/+key/...Return site config value for +key when the key is public or caller is admin; otherwise undefined.
get/Return all site configuration key/value pairs for admins, otherwise an empty list. No further lookups.

/+name marks a variable path segment. A trailing /... means extra path segments are accepted for further lookups.

Edit on GitHub

config Models admin_config

Referred by

Template Best Practices and Pitfalls

This chapter lists some preferred solutions to common tasks and pitfalls you may encounter while developing with…

config

Zotonic has two places where a site's configuration is kept: