Work with a site context

A context carries the site and request-related state used by Zotonic APIs. Pass it through your functions instead of storing one context globally.

In a trusted local shell, select the site explicitly:

C = z:c(garden).
z_context:site(C).

This creates a fresh context; it does not automatically log in an administrator. It does not reproduce a visitor's session or permissions. In a model, controller, or event handler, use the supplied request context and preserve it when the API returns an updated context.

Background work needs a deliberate context and authorization policy. See Inspect content from the Erlang shell, Keep permission checks at the boundary, and Run work outside a request.