Card
A bordered surface with an optional header, body and footer.
Strings
Plain card
A title, a description and a body string.
{ui card,
title: 'Plain card',
description: 'A title, a description and a body string.',
body: 'Strings are enough when there is no markup.',
footer: 'Last edited today',
/}
The header, body and footer each appear only when they have content, so a card can be any combination of the three. The parts are plain header, section and footer elements with no classes of their own.
With content
Sign in
Use your account email.
{ui card, title: 'Sign in', description: 'Use your account email.'}
{ui field, name: 'email', label: 'Email'}
{ui input, name: 'email', type: 'email', placeholder: '[email protected]' /}
{/ui}
{block footer}
{ui button, title: 'Continue' /}
{ui button, title: 'Cancel', class: 'button-ghost' /}
{/block}
{/ui}
Written as a pair, {ui card}...{/ui} takes its content as the body, and {block footer} fills the footer. Components inside get only their own args, so the button's title is not the card's.
One limit comes from Latte: a variable the page already has, with the same name as a card param, shows the card's value inside the card. {$title} in a card's content is the card's title.
Body only
No title, no description and no footer: only the body is drawn.
{ui card}
<p>No title, no description and no footer: only the body is drawn.</p>
{/ui}
With media
Mountain light
A card with an image above its header.
<div class="max-w-md">
{ui card,
title: 'Mountain light',
description: 'A card with an image above its header.',
}
{block media}
<img
src="{p('images')->image('luca-bravo-zajdgnxsmeg-unsplash.jpg')->src('w=800')}"
alt="A mountain ridge at dawn"
>
{/block}
{block footer}
{ui button, title: 'View', class: 'button-outline' /}
{/block}
{/ui}
</div>
{block media} fills a figure above the header, with the image running to the card's edges and following its rounded top corners. Like the footer, it only appears when it has content. An img or video in it is drawn 16 by 9 and cropped to fit; to use another ratio, put an aspect utility on the element, such as aspect-square. Give the image an alt. A string media param is escaped like any other, so markup goes in the block.
Own header
Team plan
Current{ui card, body: 'Anything in the header block replaces the title and description.'}
{block header}
<div class="flex items-center justify-between gap-2">
<h2>Team plan</h2>
{ui badge, title: 'Current' /}
</div>
{/block}
{/ui}
{block header} replaces the title and description together, for a header that needs a badge, an action or another heading level. The block is the whole header, so it appears only when it has content, like the footer. Keep an h2 in it for the heading style.