# Custom Cards

Custom cards allow you to perform more complex metric calculations and are defined via a class implementing the `Card` base class.

When Umbraco UI Builder resolves a card it will attempt to do so from the global DI container. This means you can inject any dependencies that you require for your card to calculate its value. If there is no type defined in the DI container, Umbraco UI Builder will fall-back to manually instantiating a new instance of value mapper.

## Defining a custom card

To define a card you create a class that inherits from the base class `Card` and configure it within the constructor like so.

```csharp
// Example
public class AvgPersonAgeCard : Card
{
    public override string Alias => "avgPersonAge";
    public override string Name => "Average Age";
    public override string Icon => "icon-calendar";
    public override string Color => "green";
    public override string Suffix => "yrs";
        
    public override object GetValue(object parentId = null)
    {
        // Perform value calculation logic
    }
}
```

The required configuration options are:

* **Name:** The name of the card.
* **Alias:** A unique alias for the card.
* **GetValue(object parentId = null):** A method to get the cards value.

Additional optional configuration options are:

* **Icon:** An icon to display in the card.
* **Color:** The color of the card.
* **Suffix:** A suffix to display after the card value.

## Adding a custom card to a collection

### **AddCard() : CollectionConfigBuilder\<TEntityType>**

Adds a card of the given type to the collection.

```csharp
// Example
collectionConfig.AddCard<AvgPersonAgeCard>();
```

### **AddCard(Type cardType) : CollectionConfigBuilder\<TEntityType>**

Adds a card of the given type to the collection.

```csharp
// Example
collectionConfig.AddCard(typeof(AvgPersonAgeCard));
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.umbraco.com/umbraco-ui-builder/13.latest/cards/custom-cards.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
