What are cards?#
CloudCannon uses cards to represent your data. A card is a configurable UI element that gives you a preview of that data. Depending on the type of data stored, this could include an image, title, subtitle, icon, and metadata.
Cards appear in different places across the app, including:
- Snippets
- Snippet Picker
- Structures
- Structure Picker
- Select-style inputs
- Object inputs
- Collection file lists
These cards are configurable using the preview
key.
Select-style inputs, Object inputs and Structure and non-structure inputs inside Array inputs support a subset of these options. The specifics are documented on each page.
Configure your card previews#
The preview
configuration has a number of different keys which correspond to different parts of the card display.
Preview reference#
The highest level of text shown in the preview.
The second highest level of text which is displayed over at most two lines.
Adds an icon from Google’s Material Icons beside the text and subtext on the card. Must match Material Icon name.
If an icon is set, this key will set the color of that icon. Accepts HEX values.
Defines an image to display beside the text and subtext on the card. Once the image loads it will cover the icon.
A list of items that can contain an image, icon and text. Great for related data. See metadata reference below.
Defines large image/icon preview for the card. See gallery metadata below.
metadata reference#
Metadata is a great way to show related data in the card.
The text to be displayed on the metadata item.
Defines an icon from Google’s Material Icons beside the text on the metadata. Must match Material Icon name.
If an icon is set, this key will set the color of that icon. Accepts HEX values.
Defines an image path to load over the icon.
gallery reference#
The gallery will render an icon if it is defined, an image over the icon once loaded and if neither exist the text will be displayed.
Defines text to display in the centre of the gallery area if there is no icon or image.
Defines an icon from Google’s Material Icons to display in the centre of the gallery area. match Material Icon name.
If an icon is set, this key will set the color of that icon. Accepts HEX values.
Defines an image to display in the gallery area. Covers text and icon once the image is loaded.
Sets how image is displayed in the gallery. Must be cover
(default) or contain
.
How cascading options work#
Most of the keys within preview
are the same type of structure, which we call cascading options. This is either an Array or a single value of the following types:
- A String of the exact value (e.g
"My Item"
) - A reference to a key within the connected item (e.g
key: title
in YAML or{ "key": "title" }
in JSON) - A String with placeholders that will be replaced with values (e.g.
template: {date|date_long}
in YAML or{ "template": "{date|date_long}" }
in JSON)
When using an Array each item is read in order. If no content is found, the next item in the array is used. If no content is valid, the corresponding preview
option will be hidden.
Below is an example of some data representing a Figure that needs previewed:
When displaying this Figure we want to:
- Always display the
image
icon (A String example) - In the text, display the
image_path
key falling back to the String ‘Image missing’ (An Array example) - In the subtext, display the
alt_text
key falling back to the String ‘No alternative text’ (Another Array example)
Writing this as a set of preview
options will look like this:
Template strings in previews#
You can use template strings in your card previews. Template strings are a mixture of literal text and dynamic placeholders that are replaced with data. You can use template strings to populate your card previews with more complex strings.
The template
key can reference keys from within the object you want to preview.
When using a template string, all placeholders within the string must resolve to an output. If any placeholder resolves to an empty result, CloudCannon cannot display that template string. In this case, CloudCannon will use the next item in the array.
Let's walk through an example. We want to add the author of a file to the card metadata field. We want the metadata field to have a person icon and the text "By [author name]". If no author name is available, the text should read "No author".
To achieve this, we will create an array of metadata.text
options. The first array item is our template string, with the value of template
set to By {author.name}
. The second array item is the string No author
.
In the above example, if the author.name
key in our object is set to "Heather", the card preview will display "By Heather" in the metadata field.
For more information, including a list of all available placeholder values, read our documentation on template strings.
Picker specific options#
There are two states where cards can be displayed:
- A card connected to an existing item with it’s own data (e.g an instance of a snippet or structure on a page)
- A card used in a “picker” where the type of item needs to be selected (e.g. adding a snippet or structure)
When a card is used in a “picker”, it is useful to override the options from the preview
config. For this we use the picker_preview
config which merges on top of the preview
options. The options within picker_preview
are the same as the options in preview
.
For the same figure example we used above we want to:
- Show the String ‘Figure’ for the
text
- Disable the
subtext
to prevent showing the String ‘No alternative text’