The Bookshop blueprint
of your component config can help configure
some advanced Structure use-cases on CloudCannon.
Nesting components#
Your blueprint can reference other components and Structures, which will embed their structured data within.
For example, this saves you from having to re-define the required inputs if your hero
component
contains an editable button
component — using component nesting your blueprint might look like:
This is a string, and could also be written button: "bookshop:button"
.
In this example, the button key will become an Object Structure containing the values specified in your button component blueprint. If you desired an array of buttons, you could use the following:
Or more concisely, buttons: [bookshop:button]
In general, any bookshop:<component_name>
string will be replaced with the structure of that component,
and will allow editors to add and remove that component.
Nesting a set of components#
If you're creating a layout component, you likely want to support a set of components.
For this, you can reference the keys we defined in spec.structures
:
The header
key will become a single component that can be selected from the set of components tagged as content_blocks
The inner_components
key will become an array that can contain any components tagged as content_blocks
Nesting Example#
To give a concrete example, let's say we have an example hero
component:
Then our matching component template file might look like:
Object Structures in CloudCannon may be empty, as the component can be removed and replaced, so your template should check for the existence of this component.
Initializing Nested Components#
By default, nested components using the bookshop:*
shorthand will be initialized empty. For example, the blueprint:
Will be initialized in CloudCannon as:
Where the button
input will provide an editor with the option to add a button component.
To instead have the button component exist on creation, you can use the syntax bookshop:button!
:
The same setting can be applied to a structure shorthand by specifying the component that should be initialized. Taking the following example:
This will be initialized in CloudCannon as:
Where column_components
can be then further added to/removed from by an editor,
using components from the tagged structure.