mod_base

mod_base is the base module, which acts as a container module holding most of Zotonic basic dispatch rules, Actions and Module tags.

Note that the amount of templates has been kept to a minimum in this module, so that sites are free to implement whatever templates they want. Core base module providing fundamental dispatch rules, actions, and template components used across sites.

Accepted Events

This module handles the following notifier callbacks:

  • observe_content_types_dispatch: Add an extra content-type to the 'id' controller using controller_api:content_types_provided.
  • observe_dispatch: Check if there is a controller or template matching the path using z_url:url_path_encode.
  • observe_edge_delete: If an edge is deleted, then force a repivot of the subject using z_pivot_rsc:insert_queue.
  • observe_edge_insert: If an edge is inserted, then force a repivot of the subject using z_pivot_rsc:insert_queue.
  • observe_hierarchy_updated: Renumber category ranges after hierarchy edits so tree lookups remain consistent.
  • observe_media_stillimage: Return the filename of a still image to be used for image tags using z_media_preview:can_generate_preview.

Edit on GitHub

Configuration

Configuration keys declared by this module. The defaults below are from the source code.

Module Key Type Default Description
site title string [] The title of the site, used in the HTML <title> tag and in the header.
site subtitle string [] The sub-title of the site, can used in the HTML <title> tag and in the header.
site chart_palette string [] Optional comma or whitespace separated hexadecimal RGB colors used as the default chart palette.
site pagelen integer 20 The default page length of paginated searches. Default is 20 items per page.
site session_expire_inactive integer 14400 The time in seconds after which an inactive session expires. Default is 14400 seconds (4 hours).
site autologon_expire integer 15552000 The time in seconds after which an autologon cookie expires. Default is 15552000 seconds (180 days).
site password_force_different boolean false If true, a user must choose a different password when changing their password.
site state_cookie_secret string [] The secret used to encrypt the state cookie with application state data remembered between page reloads. It is automatically set, and must be a random string that is kept secret.
site security_expires string "+1 month" The relative time after which the .well-known/security.txt expires. Default is '+1 month'.
site security_email string [] The contact email address for security issues, used in the .well-known/security.txt file. Defaults to the Zotonic config security_email, and if not set to the public mail_email address of the admin (id 1) user.
site security_url string [] The URL to the security contact, used in the .well-known/security.txt file. Defaults to the URL of the page_security_contact page, and if not set to the Zotonic config security_url.
site security_policy_url string [] The URL to the security policy, used in the .well-known/security.txt file.Defaults to the URL of the page_security_policy page, and if not set to the Zotonic config security_policy_url.
site security_hiring_url string [] The URL to the security hiring, used in the .well-known/security.txt file.Defaults to the URL of the page_security_hiring page, and if not set to the Zotonic config security_hiring_url.
site smtphost string [] The domain used for the 'from' when sending email and the SMTP hostname used for receiving email. Defaults to the site's configured hostname.
site bounce_email_override string [] If set, this email address is used as the envelop address on emails and will receive bounced emails. Defaults to the Zotonic config smtp_bounce_email_override, and if not set to the noreply with the smtphost as the domain.
site email_from string [] The email address used as the 'from' address when sending emails. Defaults to noreply with the smtphost as the domain.
site email_override string [] If set, all outgoing email will be sent to this address. Useful on development systems to catch all email. The Zotonic config email_override always takes precedence over this setting.
site email_override_exceptions string [] Comma or space separated list of email addresses and @domains that are not overridden by the email_override. Useful to allow some emails to be sent to their original destination, while others are caught by the email_override.
site client_smtphost string [] The domain hostname as identification when sending email to other SMTP servers. Defaults to the site's configured hostname.
site smtp_relay boolean false If true, the site will relay email through the SMTP server configured in smtp_relay_host. If false, the site will send email directly to the recipient's mail server.
site smtp_relay_host string [] If smtp_relay is set, the hostname of the SMTP server to relay email through. Defaults to localhost.
site smtp_relay_port integer 25 If smtp_relay is set, the port of the SMTP server to relay email through. Defaults to 25 or 587, depending on smtp_relay_ssl.
site smtp_relay_ssl boolean false If smtp_relay is set, always use SSL/TLS when connecting to the relaying SMTP server. Defaults to false, which means STARTTLS is only used if supported by the relaying server.
site smtp_relay_username string [] If smtp_relay is set, the username to authenticate with the relaying SMTP server. Defaults to an empty string, which means no authentication is used.
site smtp_relay_password string [] If smtp_relay is set, the password to authenticate with the relaying SMTP server.
site hsts boolean false If true, the site will send the Strict-Transport-Security header to enforce HTTPS connections. Defaults to false.
site hsts_maxage integer 17280000 The maximum age in seconds for the Strict-Transport-Security header. This is only useful if hsts is also set to true. Defaults to 17280000 seconds (200 days).
site hsts_include_subdomains boolean false If true, the Strict-Transport-Security header will include the 'includeSubDomains' directive. This is only useful if hsts is also set to true. Defaults to false.
site hsts_preload boolean false If true, the site will include the 'preload' directive in the Strict-Transport-Security header. This is only useful if hsts is also set to true. Defaults to false.

Observes

Notifications

observe_content_types_dispatch/3

Get available content types and their dispatch rules Example: {{<<”text”>>, <<”html”>>, []}, page} A special dispatch rule is ‘page_url’, which refers to the…

Notifications

observe_edge_delete/2

An edge has been deleted Note that the Context for this notification does not have the user who deleted the edge.

Notifications

observe_dispatch/2

Final try for dispatch, try to match the request. Called when the site is known, but no match is found for the path

Notifications

observe_media_stillimage/2

See if there is a ‘still’ image preview of a media item. (eg posterframe of a movie) Return:: {ok, ResourceId} or undefined

Notifications

observe_edge_insert/2

An edge has been inserted. Note that the Context for this notification does not have the user who created the edge.

Models

Models

mqtt_ticket

A ticketing system for out of band MQTT posts via HTTP.

Cotonic models

Cotonic models

model/loadmore Cotonic

model/loadmore Replaces a loader element with a server-rendered template. Include js/models/loadmore.js from mod_base on pages that use this model.

Controllers

Controllers

controller_api

controler_api processes authorized REST API requests: It provides an easy way to create API calls to allow computer programs to perform functions on your…

Controllers

controller_file

Serve an uploaded-, resized- or library file.

Controllers

controller_id

Handle different content representations of a page.

Controllers

controller_media_runner_callback

Client-side receiver for results produced by the external media runner site. This controller belongs to mod_base , so each client site has a callback endpoint…

Controllers

controller_ping

Simple controller for connection tests, used on the /test/connection page.

Dispatch rules

Dispatch rules

mod_base dispatch rules

URL dispatch rules defined by mod_base in apps/zotonic_mod_base/priv/dispatch/dispatch.

Filters

Filters

add_day

Adds a day to a date. The value must be of the form {{Y,M,D},{H,I,S}} .

Filters

add_hour

Adds an hour to a date. The value must be of the form {{Y,M,D},{H,I,S}} .

Filters

add_month

Adds a month to a date. The value must be of the form {{Y,M,D},{H,I,S}} .

Filters

add_week

Adds a week to a date. The value must be of the form {{Y,M,D},{H,I,S}} .

Filters

add_year

Adds a year to a date. The value must be of the form {{Y,M,D},{H,I,S}} .

Filters

after

Return the first element after another element in a list. For example:

Filters

append

Appends the argument to the value.

Filters

as_atom

Convert a value to an Erlang atom.

Filters

before

Return the first element before another element in a list. For example:

Filters

brlinebreaks

Translate HTML <br/> elements into ASCII newlines ( \n ).

Filters

capfirst

Converts the first character of the value to uppercase.

Filters

center

Centers the value in a field of a certain width using spaces.

Filters

chunk

This filter splits a list in shorter lists. It splits an array in sub-arrays of at most a given length. This is useful when displaying a list of items in…

Filters

content_type_label

Return a translated, human-readable label for a MIME content type.

Filters

content_type_urls

Return the available content representations and URLs for a resource.

Filters

date

Formats a date or datetime according to the format specified in the argument.

Filters

datediff

Calculate the difference between two dates, returning a single part of that difference.

Filters

default

Provide an alternative value in case a value has a falsy value (0, false , undefined or empty string).

Filters

default_if_none

Provide an alternative value in case a value is undefined.

Scomp

Scomp

chart

Render a chart without JavaScript, CSS, external services, or external assets.

Scomp

chart_donut

Render a donut chart as inline SVG.

Scomp

chart_pie

Render a pie chart as inline SVG.

Scomp

chart_pie3d

Deprecated compatibility alias for scomp#chart_pie.

Scomp

debug

Shows which variables are assigned for use in the current template’s scope:

Scomp

lazy

Custom tag which adds a ‘loader’ image to the page and performs a one-time action when loader comes into view.

Scomp

loremipsum

Inserts a piece of “lorem ipsum” text into the page.

Scomp

pager

Show a pager for search results.

Scomp

spinner

Add an AJAX activity indicator.

Scomp

tabs

Make a HTML element into a tab set.

Scomp

worker

Start a named Cotonic worker from a template.

Validators

Validators

acceptance

Check if an input value evaluates to true.

Validators

custom

Support for custom client-side (JavaScript-based) validators.

Validators

date

Validate input date against a given date format.

Validators

email

Check if the content of the input field is an e-mail address.

Validators

format

Regular expression test.

Validators

json

Validate that a form value is JSON.

Validators

length

Check the length of a text input.

Validators

name_unique

A validator to check whether a resource’s name is unique:

Validators

page_path_unique

A validator to check whether a resource’s page path is unique:

Validators

postback

Performs a custom server side validation of an input value. This allows you to add your own validation logic to HTML form fields.

Validators

presence

Check if an input has been filled in or checked.

See also

Modules

mod_custom_redirect

Enables redirects from unknown hosts and paths to other locations. The other location can be a known path or another web site.

Developer guide

Follow a request to its template

Start with the URL that gives an unexpected result. Check its hostname: Zotonic uses it to select a site before matching the site's dispatch rules.

Referred by

Modules

mod_custom_redirect

Enables redirects from unknown hosts and paths to other locations. The other location can be a known path or another web site.

Developer guide

Add an HTTP controller

Use controller_template when a dispatch rule only needs to render a template. Write a custom controller when the endpoint needs additional request processing…

Developer guide

Follow a request to its template

Start with the URL that gives an unexpected result. Check its hostname: Zotonic uses it to select a site before matching the site's dispatch rules.