Cards

A grid of cards, one per row, or one per item of a collection: image, text and link.

When to use it

A few things of the same kind shown side by side, each with an image, a short text and a link: services, trips, rooms, team members. It can also show one card per item of a collection.

When not to

Long text (cards are for scanning) and lists of pages that change often: list-pages fills itself from a folder. For a single highlighted page, use a teaser.

Accessibility

A list, so screen readers say how many cards there are. When every card has the same link text, such as "Learn more", SeedPage adds the card's title to it out of sight so each link says where it goes. Give every image a description.

See it live

The component library shows this component in the default theme, in every variant: open it in the component library

The cards example as the component library shows it in the default theme

Where it is used

The starter sites that use it, each at a page that shows it:

Fields

What the component’s dialog asks for. In a Doc, keyed rows start with the key; rows in order follow the order below. Each row is one item, its cells in the order of the fields.

Field

Key

Kind

Required

Image

image

An image from the assets, with its description

No

Text

text

Text with headings, lists, links and bold

No

Link

link

A link: its text and address

No

Collection (a Sheet or JSON file in the data folder)

source

A value from a short list, or a setting

No

How many

limit

A value from a short list, or a setting

No

Order

sort

A value from a short list, or a setting

No

Keep only the items whose field or column has a value, as category = Mains or start >= today

filter

A value from a short list, or a setting

No

Variants

A variant changes how the component looks. Write it in parentheses after the name in the table’s first cell, several separated by commas.

Variant

Write in the first cell

Two columns

cards (2-colunas)

Three columns

cards (3-colunas)

From a collection

Instead of writing its items one by one, the block can show the items of a collection: a Sheet tab or a JSON file in the content/data folder. Add these rows to the table, a name in the first cell and its value in the second:

  • source: the name of the collection, such as menu (required)
  • sort: the column to order the items by; a minus before it, such as -date, orders them backwards
  • limit: the most items to show
  • filter: keep only the items whose column has a value, such as category = Mains

The first row of the collection names its columns. A name that matches no collection raises the warning unknown_data_source.

Warnings it can raise

The editor and the build say these when a block of this component needs a fix. All warnings are listed in the warnings reference.

Code

What it says

unknown_data_source

No collection named "{source}" in the data folder.

In Google Docs

A component is a table. Its first cell names it; the rows below hold its fields. This is the example table: The first row of the table here only names the columns; the Doc table is the rows below it.

Image

Text

Link

cards

[Image]

Climbing — Routes for every level.

See trips (https://example.com/climbing/)

[Image]

Cycling — Forest and coast.

See trips (https://example.com/cycling/)

In a page file

In a site kept as a folder or in Git, the same component is a block of the page’s JSON file:

JSON
{
  "name": "cards",
  "variants": [
    "2-colunas"
  ],
  "rows": [
    [
      {
        "image": "Climbers on a ridge"
      },
      {
        "title": "Climbing",
        "text": "Routes for every level."
      },
      {
        "link": "See trips",
        "href": "https://example.com/climbing/"
      }
    ],
    [
      {
        "image": "Bikes on a forest trail"
      },
      {
        "title": "Cycling",
        "text": "Forest and coast."
      },
      {
        "link": "See trips",
        "href": "https://example.com/cycling/"
      }
    ]
  ]
}

Markup and classes

What the component writes takes these classes, for a theme’s CSS: the component’s own name, name__part for its parts and name--variant for each variant (the variant’s plain name is there too).

Class

What it marks

cards

The component

cards__body

A part of it

cards__item

A part of it

cards--2-colunas

A variant

cards--3-colunas

A variant

The HTML the example above writes, as the component library builds it in the default theme:

html
<ul class="cards">
    <li class="cards__item">
      <img src="/assets/img/5521e01d770e-1600.webp" srcset="/assets/img/5521e01d770e-400.webp 400w, /assets/img/5521e01d770e-800.webp 800w, /assets/img/5521e01d770e-1600.webp 1600w" sizes="(max-width: 800px) 100vw, 800px" alt="Climbers on a ridge" width="1800" height="900" fetchpriority="high" decoding="async">
      <div class="cards__body"><p><strong>Climbing</strong></p><p>Routes for every level.</p></div>
      <a class="button" href="https://example.com/climbing/">See trips<span class="visually-hidden">: Climbing</span></a>
    </li>
    <li class="cards__item">
      <img src="/assets/img/5521e01d770e-1600.webp" srcset="/assets/img/5521e01d770e-400.webp 400w, /assets/img/5521e01d770e-800.webp 800w, /assets/img/5521e01d770e-1600.webp 1600w" sizes="(max-width: 800px) 100vw, 800px" alt="Bikes on a forest trail" width="1800" height="900" loading="lazy" decoding="async">
      <div class="cards__body"><p><strong>Cycling</strong></p><p>Forest and coast.</p></div>
      <a class="button" href="https://example.com/cycling/">See trips<span class="visually-hidden">: Cycling</span></a>
    </li>
</ul>

Visitor texts

Texts it shows visitors, in the page’s language. Every one is in the visitor texts reference.

Key

Text

site.cards.more

Learn more

Extending it

Its files in SeedPage. A theme or a site changes the markup by giving a file of the same name (the Liquid part), and a new component can extend this one.

  • src/components/cards.js
  • src/components/cards/action.liquid
  • src/components/cards/body.liquid
  • src/components/cards/cards.liquid
  • src/components/cards/media.liquid