# mod\_base

Source: https://zotonic.com/docs/1296/mod_base

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

Language: en



mod\_base is the base module, which acts as a container module holding most of Zotonic basic [dispatch rules](/id/dispatch), [Actions](/id/template_action#actions) and [Module tags](/id/template_tag#scomps).

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.

Theme initialization
--------------------

The selected UI theme depends on the site.ui\_theme configuration. If the config is set to 'user' then the user can select a theme, and if they did not select one then the theme defaults to 'auto'. Any other ui\_theme ('auto', 'dark', or 'light') fixes that theme and disables the theme selector in the admin interface.

The common HTML head includes `_html_head_theme_init.tpl`. This template runs a small inline script before the main CSS is applied, so pages start with the right theme and avoid a light/dark flash during rendering.

The template is included from both `_html_head.tpl` and `_html_head_admin.tpl`, so it is applied to normal site pages and admin pages that use the standard Zotonic head templates.

The script sets two attributes on `document.documentElement`:

- `data-zotonic-theme`: the selected theme preference, one of `light`, `dark` or `auto`.
- `data-bs-theme`: the resolved Bootstrap theme, either `light` or `dark`. When the selected preference is `auto`, this follows `prefers-color-scheme: dark`.

The selected preference is stored in `localStorage` under the key `zotonic-theme`. The stored value is JSON encoded, for example `"dark"`, so it can also be read and written through Cotonic `model/localStorage`. If the value is missing, invalid JSON, or not a supported theme, templates and client-side code fall back to `auto`.

CAFS configuration
------------------

The base module lists the core content-addressable file storage settings in the admin configuration catalog. These are per-site `m_config` settings in the `site` namespace; they do not require `mod_filestore` or a separate CAFS module.

| Key                                | Default | Description                                                                      |
| ---------------------------------- | ------- | -------------------------------------------------------------------------------- |
| `site.cafs_preview_retention_days` | `90`    | Grace period for obsolete previews, in days. Valid values are 1 through 3650; invalid values use 90. Cleanup is lazy, and other valid usages preserve shared output. Requests do not extend the grace period. |
| `site.cafs_renderer_version`       | `1`     | Additional image renderer version. Change after rendering changes not already captured in the generation key, then call `z_file_sup:refresh/0` to invalidate running file entries. New previews are generated on demand. |

See <a href="/id/doc_model_model_m_cafs" class="doc-reference doc-reference-model"><code>model#m_cafs</code></a> for source recovery retention, shared preview collection, and remote storage behavior.

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`.

License: 

Attribution: 

Related resources: https://zotonic.com/api/agent/related/1296?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/1296?language=en>)
