Use stable resource names

A resource has a numeric ID within its database. Give application-owned resources a stable name when code needs to find them across installations.

Id = m_rsc:rid(page_home, C).

Check the result before using it: that name may not exist on your site. A database ID copied from another site can identify unrelated content. Use a stable name, URI, or explicit import mapping when moving data between sites.

Reserve names for resources your application can identify consistently. Editors can still manage their titles and bodies. See model#rsc, Install initial content with a datamodel, and Move content between sites.

Read and update resource properties

Use model#rsc to read resources and m_rsc_update for writes. Use the supplied request context so the operation keeps the caller's site and permissions.

In an authorized local test context, with an existing garden_welcome resource:

Id = m_rsc:rid(garden_welcome, C).
m_rsc:is_visible(Id, C).
m_rsc:p(Id, title, C).
m_rsc_update:update(Id, #{<<"summary">> => <<"Visit the garden on Saturday.">>}, C).

Check that Id is an integer before continuing. Expect {ok, Id} from a successful update; {error, Reason} is a failed write, not a saved page. Read the summary back and check the rendered page. The ordinary z:c(garden) shell context does not grant editing permission.

In application code, branch on visibility before returning private properties and on the update result before reporting success. The write API checks access, but you must still select and validate the fields the caller may change. Do not copy every submitted field into the resource or update the SQL table directly.

Connect resources and preserve order

An edge connects a subject resource to an object resource through a predicate. Use model#edge to inspect and manage these connections.

For example, in a local shell:

m_edge:objects(Id, haspart, C).

Use the edge API for insertions, deletions, and ordering. Direct database writes skip normal notifications and cache invalidation. Check permissions on the requested relationship as well as the resource being edited.

When importing a collection, preserve the order of its children explicitly. A set of correct connections in the wrong order can still produce the wrong navigation. See Move content between sites and Install initial content with a datamodel.

For two existing, authorized resources, connect a guide to its first task:

{ok, _EdgeId} = m_edge:insert(GuideId, haspart, TaskId, C).
m_edge:objects(GuideId, haspart, C).

The pattern match is useful in a test shell; application code must handle {error, Reason}. Use relation for related tasks and a site's hasreference predicate for citations, when that predicate exists. Neither should change collection membership.

m_edge:set_sequence(GuideId, haspart, OrderedIds, C) sets the requested outgoing list; it can add or remove membership as well as reorder it. Read the current list first and supply the complete intended list. Verify it with m_edge:objects/3. Do not use this operation to overwrite connections owned by editors during a routine import.

Referred by

Documentation

Glossary

Action An action is functionality that can be attached to a HTML element or event. Actions are wired to an element or event. Think of showing dialogs, posting…

Developer guide

Create a page layout

Use an existing site base template as your starting point. Put shared document structure in the base and page-specific markup in blocks.

Developer guide

Search

Query arguments and terms for searching pages using the search APIs.