Content and data

Read, connect, search, and manage site content from code.

Choose the task that matches what you need to do. The pages explain the relevant workflow and link to related guides and reference material. Examples use the local site garden; use your own site name and check the command’s scope before running it.

In this section

  1. 1Work with a site contextA context carries the site and request-related state used by Zotonic APIs. Pass it through your functions instead of storing one context globally.
  2. 2Use stable resource namesA resource has a numeric ID within its database. Give application-owned resources a stable name when code needs to find them across installations.
  3. 3Read and update resource propertiesUse model#rsc for resource access and m_rsc_update for writes. These APIs handle behavior that a direct SQL update would bypass.
  4. 4Model content with categories and predicatesUse a category to describe what a resource is, such as an article or event. Use a predicate to describe a relationship between two resources, such as an author or subject.
  5. 5Connect resources and preserve orderAn edge connects a subject resource to an object resource through a predicate. Use model#edge to inspect and manage these connections.
  6. 6SearchQuery arguments and terms for searching pages using the search APIs.
  7. 7Work with uploaded mediaA media resource has ordinary content properties and information about its associated file. Use model#media to inspect and manipulate media through Zotonic's normal processing path.
  8. 8Install initial content with a datamodelUse a datamodel for application-owned categories, predicates, resources, and relationships that must exist when a module is installed.
  9. 9Keep permission checks at the boundaryUse the request context when checking access to data and actions. A hidden button is not an authorization check: callers can invoke a model or endpoint directly.
  10. 10Add a database query when models are not enoughPrefer Zotonic models for resources and edges. Use z_db for application tables or queries that the model APIs do not cover.
  11. 11Move content between sitesExport structured resource data and record how source resources map to destination resources. Match stable names or URIs deliberately; do not assume that numeric IDs match across sites.