Components
What Is a Component?
A component is the smallest unit of managed content on a page. Every piece of visible content — a heading, a block of rich text, an image, a call-to-action button, a conference card — is a component.
Components are:
- Stored in the API as entities in your database (each type is a PHP class)
- Rendered by the Nuxt module using matching Vue files
- Edited inline in the browser by editors without leaving the page
A Component Has Two Sides
1. The PHP entity (the data)
#[Silverback\Publishable]
#[ApiResource(mercure: true)]
#[ORM\Entity]
class Title extends AbstractComponent
{
use PublishableTrait;
#[ORM\Column(nullable: true)]
public ?string $title = null;
}
AbstractComponent gives it identity (IRI, UUID) and the uiComponent field. You add your own data fields.
2. The Vue component (the display)
<!-- app/app/cwa/components/Title/Title.vue -->
<template>
<h1>{{ resource?.data?.title || 'No Title' }}</h1>
</template>
<script setup lang="ts">
import type { IriProp } from '#cwa/composables/cwa-resource'
import { useCwaComponent, defineCwaConfig } from '#imports'
defineCwaConfig({
name: 'Title',
description: 'The main heading of a page',
icon: 'heading',
})
const props = defineProps<IriProp>()
const { resource, exposeMeta } = useCwaComponent(props)
defineExpose(exposeMeta)
</script>
The module passes the component's IRI as a prop. useCwaComponent reads the resource from the module's store — the module has already fetched it — and stays reactive to updates. defineExpose(exposeMeta) wires the component into the admin manager.
defineCwaConfig holds the component's settings, in its own file: how the Add Component dialog shows it, and any styles editors can choose. There's no list of components to keep in nuxt.config: the module finds each one from its folder in app/app/cwa/components/.
The Admin Tab
An admin tab is a separate Vue file that renders inside the manager panel when this component is selected in edit mode.
<!-- app/app/cwa/components/Title/admin/Title.vue -->
<template>
<CwaUiManagerTab>
<CwaUiInput field="title" label="Title" width="lg" />
</CwaUiManagerTab>
</template>
<script setup lang="ts">
import { useCwaResourceManagerTab } from '#imports'
const { exposeMeta } = useCwaResourceManagerTab({ name: 'Title' })
defineExpose(exposeMeta)
</script>
A tab is one <CwaUiManagerTab> holding the module's admin fields, such as CwaUiInput, CwaUiSelect, CwaUiToggle and CwaUiFileUpload. field="title" binds the input to the component's title: each change is sent to the API as a PATCH a moment after the editor stops typing. There's no save button.
Editing on the page
A tab is a single row, so it has no box for text that runs to several lines. That text is edited on the page instead. In edit mode the template's Title also renders <LazyCwaUiInlineEdit>, so editors can click the heading and type, and HtmlContent is edited in place with TipTap. A tab can point editors there with <CwaUiInlineHandoff field="html" label="Content" />. Component Files has the details.
<Type>.vue displays it, admin/ holds its tabs and ui/ its other looks. A helper component goes in _parts/, which the module ignores.Component Patterns
Looking at real-world usage, a few patterns come up constantly:
| Pattern | Example | What it needs |
|---|---|---|
| Text field | Title, TextBlock | useCwaComponent + a CwaUiInput in the tab, as in Your First Component |
| File upload | Image, HeroSection | useCwaComponent + withFile() + a CwaUiFileUpload in the tab, see Images & Media |
| Rich text | HtmlContent | useCwaComponent + a TipTap editor on the page, see HTML Content |
| Link | NavigationLink | Text + Route/URL fields, see <CwaLink> |
| Parent + children | Accordion, Gallery | CwaComponentGroup inside the parent component, see <CwaComponentGroup> |
| Form | Contact form | A Form/ui/<Name>.vue variant of the module's own Form component, see Forms |
| Collection listing | Blog list | Built-in Collection component, see Collections & Pagination |
Alternative UI Variants
A component can have more than one look. The same NavigationLink data might render as a plain text link, a filled button, or an icon, depending on what an editor selects.
There are two ways to provide them:
- Styles — declared in
defineCwaConfigasstyles: { key: { label, classes } }. The component stores the keys an editor picks (asstyle:<key>inuiClassNames), and the module applies their classes to its root element - UI variants — create
app/app/cwa/components/Title/ui/AlternativeName.vueas a full alternative template. It registers asCwaComponentTitleUiAlternativeName, the name the admin stores inuiComponentwhen it is picked. A variant offers the component's styles unless it declares its own
Both approaches are covered in the Alternative UI Variants guide.
Publishing
Most components use the #[Silverback\Publishable] annotation. This means:
- Editors change a draft version — the live site is unaffected
- Changes become live when the editor clicks Publish
- Mercure broadcasts the update so visitors see the new content in real-time
See Draft & Publish for details.
Next: Draft & Publish
Draft & Publish explains how a publishable component's draft and published versions work.