Skip to main content

Module component

Module component 

Source
Expand description

Components: compiled units a page or layout attaches, each producing data a template reads under the alias it was attached as.

A module implements Component and registers a ComponentReg. A page or layout attaches one in its settings under components, keyed by alias, naming the component and its properties; a property written as {{ :name }} takes the URL parameter of that name at request time:

{
  "url": "/blog/:slug",
  "components": {
    "post": { "component": "acme.post", "slug": "{{ :slug }}" },
    "latest": { "component": "acme.posts", "limit": 5 }
  }
}

The site runs every attached component before the page renders, in the order attached (the layout’s first, then the page’s, a page alias winning over a layout’s), and exposes each result as {{ post }} and {{ latest }} plus any variables a component injects into the page scope. A save checks the attachment: the component must be registered and every property one it declares, of the kind declared.

Structs§

Attachment
One attachment: an alias, a component code and its raw properties.
ComponentContext
What a component runs with.
ComponentOutput
What a component produced.
ComponentReg
A registered component: its vendor.name code, a label for the editor, and the unit.
PropertyDef
A property a component declares, for the editor and the save-time check.
Ran
What running the attachments of a page gave: a value per alias, then the injected variables, as pairs for the render context.

Enums§

PropertyKind
What a component property holds.

Constants§

ALIASES_KEY
The context key holding each alias’s component code for component().

Traits§

Component
A compiled unit a page attaches.

Functions§

attached
The attachments in a settings bag’s components, in the order written.
check
Checks a bag’s attachments against the registered components: each named one exists, each property is declared and of its kind (a {{ :name }} reference passes for any kind), and every required one is set.
install_markup
Adds every registered component’s default markup to env, so component() can fall back to it.
resolve
The properties a component runs with: the attachment’s, with {{ :name }} resolved from params and the declared defaults filled.
run_all
Runs every attachment in bags (a layout’s, then a page’s; a later alias replaces an earlier one), returning the context pairs.
template_name
The environment name of a component’s default markup.