Components
Goal: know how the components editors place on Drupal Canvas pages are created, identified, and kept in sync when your app is the renderer.
What you’ll have when you’re done
Section titled “What you’ll have when you’re done”- A working model of where components live in the app, what gives one its identity, and when the site learns about it.
- The rules that decide whether a component is offered for placement, and who is allowed to change what.
Prerequisites
Section titled “Prerequisites”- An app registered with your site, from the quickstart; its component directory already ships a working set (
Hero,Card,Accordion, and more).
-
Know where components live.
componentDirincanvas.config.jsonat the project root is the single source:componentsin the Next.js template,src/componentsin Astro,app/componentsin Nuxt. Each component is a directory holding itscomponent.yml(metadata), source file, and CSS file, the shapenpx canvas scaffoldwrites in the quickstart’s component scaffold step. An app component you already have becomes a Canvas component by gaining acomponent.ymlbeside it. -
Give each component its identity.
machineNameincomponent.ymlis the component’s identity in Canvas and the key your app’s generated registry renders by. The scaffolder writes the placeholderhello-worldinto every new component, so the second scaffold collides with the first until you change it.machineNamedoes not have to match the directory name, but a name that does is easier to live with. ChangemachineNamelater and Canvas treats it as a different component: the new name registers, and the old entry is deactivated.Hand your agent this page’s Markdown export (the
View as Markdowncontrol at the top) for the identity and status rules, then the edit:In components/<name>/component.yml set machineName to <name> and status: true.machineName is the component's identity; renaming it later registers a newcomponent and deactivates the old one. -
Decide what editors can place.
status: trueoffers the component for placement; a component left at the scaffolder’sstatus: falsestill synchronizes, and the site records it, but the library does not offer it. Nobody can rename an external component or flip its status from the editor: its identity belongs to the app that implements it, so both changes happen incomponent.yml. -
Let synchronization do the rest. There is nothing to push. Canvas reads your app’s component metadata endpoint when the editor loads and registers every component it finds, so a reload after a change is what publishes it to the library. The props declared in a component’s
component.ymlappear as editable fields in the editor’s right-hand panel when that component is placed. Components that already exist on the site come the other way:npx canvas pullbrings them into the app’s codebase in the same format.
When something goes wrong
Section titled “When something goes wrong”A component is missing from the library
check its component.yml. status left at false registers without offering; machineName left at hello-world collides with the previous scaffold. Fix the file and reload the editor, since components synchronize when it loads.
Next steps
Section titled “Next steps”- Component development guide: the authoring model itself: props as JSON Schema, slots, styling, and composition.
- Prop type declarations: the exact schema that declares each prop type the editor offers, single- and multi-value.
- First fetch: the advanced path, when a component’s page is not enough and you need the content as data.
Was this page helpful?
What went wrong?
Still stuck? Contact Acquia Support (opens in a new tab)