Components
Components are reusable, configurable, self-contained bits of the web.
Last updated
Components are reusable, configurable, self-contained bits of the web.
Last updated
The anatomy of a component simple, it's just a JSON object.
When we talk about a "component", we're generally talking a blueprint for JSON data. This blueprint is then used for an unlimited number of JSON objects which all have the same structure but can all have different data. Make sense?
So if a component is just a blueprint for data we can refer to each individual JSON object as an instance of a component, with each instance being unique.
This concept of what a component is and how a component can have multiple instances forms the basis for all of Clay.
More details about the component API can be found in the Amphora documentation, but the basics are outlined below.
To view all available components in a Clay instance visit the /_components
route:
To view the default data for a component simply request a component by name:
To view all instances of the component:
To view a single instance of the component:
In this way you can see that the component API has the following structure:
<SITE HOST>/<SITE PATH (OPTIONAL)/_components/<COMPONENT NAME>/instances/<INSTANCE ID>
Understanding this structure makes it possible to create, read, update and delete component data in your Clay instance.
Components live in three places:
On their own! All components and their individual instances are fully available at their REST endpoints
Some simple rules when making components are as follows:
If you want data that is shared between many pages, put a component in a layout.
If you want data that is not shared between pages, put a component in a page.
: page-level components are unique to a certain page
: layout-level components are shared on every page that uses a certain layout.