Creating a custom reusable "Card" pattern in OutSystems is a common and excellent practice for building modular and maintainable UI. The best way to achieve this is by creating a UI Block (known as a "Web Block" in Traditional Web, but the concept is the same for Reactive Web and Mobile).
This guide will focus on Reactive Web / Mobile, as it's the modern approach and offers the powerful "Slots" feature for dynamic content injection.
Understanding the Core Components
Before diving in, let's understand the OutSystems features we'll use:
UI Block: The container for your reusable UI.
Slots: (Reactive/Mobile only) These act as "holes" in your Block where the consuming screen/Block can inject any content. Perfect for dynamic card content (header, body, footer).
Input Parameters: Allow you to pass data or configuration into the Block (e.g., IsClickable, HasShadow, CustomCSSClass).
Events: (Optional) If your card needs to notify the parent screen about an action (e.g., OnCardClick).
Block Stylesheet: Dedicated CSS for your Block, keeping styles encapsulated.
Step-by-Step Guide to Create a Custom Card UI Block
Let's create a Card UI Block that can have a header, content, actions, be clickable, and have a shadow.
1. Create the UI Block
In Service Studio, go to the Interface tab.
Right-click on UI Flows (or a specific UI Flow like "MainFlow") and select Add UI Flow. You can also create it directly under an existing UI Flow.
Right-click on your new UI Flow (or existing one) and select Add UI Block.
Name your UI Block: Card (or CustomCard, AppCard, etc., to avoid conflict with OutSystems UI's built-in Card).
2. Define the Structure with Slots
Inside your Card UI Block:
Drag a Container widget onto the canvas. This will be the main wrapper for your card.
Give it the Name property: CardWrapper
Add the Style Classes property: card custom-card (we'll define custom-card later, card is a helpful base from OutSystems UI).
Inside this CardWrapper Container, add three Slot widgets:
Drag a Slot widget. Name it CardHeader.
Drag another Slot widget. Name it CardContent.
Drag a third Slot widget. Name it CardActions (for buttons/links at the bottom).
Optional: Default Slot Structure
To make it easier for consumers, you can pre-define simple containers inside each slot to guide them:
Inside CardHeader Slot, you could have a Container with class custom-card-header padding-m.
Inside CardContent Slot, a Container with class custom-card-content padding-m.
Inside CardActions Slot, a Container with class custom-card-actions padding-m.
The user will then drag their content into these default containers.
Your widget tree in the Card Block should look something like this:
These parameters will allow you to customize the card from where it's used.
In the Card Block, go to the Properties pane.
Click on Add Input Parameter.
Name:IsClickable
Data Type:Boolean
Default Value:False
Description: "Set to True to make the entire card clickable."
Add another Input Parameter:
Name:HasShadow
Data Type:Boolean
Default Value:False
Description: "Set to True to add a shadow effect to the card."
Add another Input Parameter:
Name:CustomClass
Data Type:Text
Default Value:""
Description: "Add custom CSS classes to the card wrapper."
4. Implement Logic for Input Parameters
For HasShadow:
Select the CardWrapper Container.
In its Style Classes property, add an expression:
"card custom-card" + If(HasShadow, " has-shadow", "") + If(IsClickable, " is-clickable", "") + If(CustomClass <> "", " " + CustomClass, "")
This dynamically adds has-shadow, is-clickable, and CustomClass based on the input parameters.
For IsClickable:
We need an OnClick event for the CardWrapper.
Select the CardWrapper Container.
In the Events section of its properties, find OnClick.
Click (New Client Action). Name it CardWrapper_OnClick.
Expose an Event: Inside the CardWrapper_OnClick action, drag an Event element from the toolbox.
Name the Event: CardClicked
Important: Go back to the Card UI Block's properties. You'll see a new section for Events. You can make CardClicked mandatory or optional here.
Now, back on the CardWrapper Container, set its OnClick property to CardWrapper_OnClick.
To only enable the click if IsClickable is true:
Wrap the CardWrapper Container in an If widget.
Condition: IsClickable
In the True branch, put the CardWrapper with its OnClick set to CardWrapper_OnClick.
In the False branch, copy the CardWrapper (without the OnClick handler) and remove the is-clickable class logic if you prefer separate styling for non-clickable cards. Alternatively, you can manage all styling with just the conditional classes. The current approach with conditional class is-clickable is usually sufficient for styling.
code
5. Add CSS Styling (Block Stylesheet)
In the Card UI Block, right-click on the Card Block itself in the widget tree.
Select Add Stylesheet.
Add the following CSS. This is where you define the look and feel. You can use OutSystems UI variables (var(--color-neutral-0)) for consistency.
css
/* Base styles for your custom card */
.custom-card {
background-color: var(--color-neutral-0); /* White */
border: 1px solid var(--color-neutral-3); /* Light grey border */
border-radius: var(--border-radius-soft); /* Soft corners */
overflow: hidden; /* Ensures content respects border-radius */
display: flex;
flex-direction: column; /* Stacks header, content, actions vertically */
}
/* Styles for shadow */
.custom-card.has-shadow {
box-shadow: var(--shadow-small); /* Small shadow from OutSystems UI */
}
/* Styles for clickable cards */
.custom-card.is-clickable {
cursor: pointer;
transition: box-shadow 0.2s ease-in-out; /* Smooth transition on hover */
}
.custom-card.is-clickable:hover {
box-shadow: var(--shadow-medium); /* Slightly larger shadow on hover */
border-color: var(--color-primary-3); /* Optional: highlight border on hover */
}
/* Header styling */
.custom-card-header {
padding: var(--space-m);
/* If header has content, add bottom border */
border-bottom: 1px solid var(--color-neutral-3);
}
/* Hide header border if slot is empty */
.custom-card-header:empty {
border-bottom: none;
padding-bottom: 0;
}
/* Content styling */
.custom-card-content {
padding: var(--space-m);
flex-grow: 1; /* Allows content to take up available space */
}
/* Actions/Footer styling */
.custom-card-actions {
padding: var(--space-m);
border-top: 1px solid var(--color-neutral-3); /* Separator for actions */
display: flex;
gap: var(--space-s); /* Space between action items */
justify-content: flex-end; /* Align actions to the right */
}
/* Hide actions border if slot is empty */
.custom-card-actions:empty {
border-top: none;
padding-top: 0;
}
6. Using Your Custom Card Block
Go to any Screen or another UI Block where you want to use your card.
From the Interface tab in the toolbox, find your Card Block under the appropriate UI Flow.
Drag the Card Block onto your screen/Block.
You'll now see the Card Block with its Slots and Input Parameters.
Fill the Slots: Drag any widgets (Text, Image, Button, Expression, other Blocks) directly into the CardHeader, CardContent, and CardActions slots. Whatever you put there will be rendered inside your card.
Set Input Parameters: In the Card Block's properties, set IsClickable to True or False, HasShadow to True or False, and add any CustomClass you need.
Subscribe to Event (if clickable): If IsClickable is True, you'll see the CardClicked event available in the Card Block's properties. Click (New Client Action) to create a handler for when the card is clicked.
Important: You can also define these styles in your Module's Theme CSS if you want them globally available or if you plan to override existing OutSystems UI card styles. However, encapsulating them in the Block's stylesheet is generally better for reusability and maintainability.