Client CraftClient Craft HubStart free

Add a pricing table backed by a data source

On this page
Updated 24 Nov 20263 min read

Register a data source with your price options and build a pricing table: a Collection repeats one card per price, with empty states.

Plan: Free Visual Builder package. The Client Craft offers source works on all plans

Goal: a pricing section whose cards come from code, so prices are changed in one place and every page shows the same numbers. A developer writes one provider; an editor designs the card once and the Collection repeats it.

Before you start #

  • Visual Builder installed and turned on.
  • The page's grid allows the Visual Builder Collection and Text blocks. In Settings › Data types, open your Block Grid, Add block and pick Collection and Text. See Show data from a data source in a block.
  • Where your prices live. This recipe reads them from configuration so it runs anywhere; swap in your own service.

Step by step #

  1. 1
    Add the price options to configurationIn appsettings.json (fictional prices):
    json
    1{
    2 "PricingTable": {
    3 "Plans": [
    4 { "Key": "basic", "Name": "Basic", "Amount": 19, "Currency": "EUR", "Period": "per month" },
    5 { "Key": "team", "Name": "Team", "Amount": 49, "Currency": "EUR", "Period": "per month" },
    6 { "Key": "business", "Name": "Business", "Amount": 99, "Currency": "EUR", "Period": "per month" }
    7 ]
    8 }
    9}
  2. 2
    Write the providerAdd PricingPlansProvider.cs to the website project. It describes a collection source and returns one record per plan:
    csharp
    1using ClientCraft.VisualBuilder.Umbraco.Data;
    2using Microsoft.Extensions.Configuration;
    3
    4namespace MySite.Pricing;
    5
    6public sealed class PricingPlansProvider(IConfiguration configuration) : IVisualDataProvider
    7{
    8 public VisualDataSource Describe() => new(
    9 "pricing-plans",
    10 "Pricing plans",
    11 [
    12 new VisualDataField("name", "Plan name", VisualDataKind.Text),
    13 new VisualDataField("price", "Price", VisualDataKind.Money),
    14 new VisualDataField("period", "Billing period", VisualDataKind.Text)
    15 ]) { IsCollection = true };
    16
    17 public Task<VisualDataResult> ResolveAsync(VisualDataContext context, CancellationToken cancellationToken)
    18 {
    19 cancellationToken.ThrowIfCancellationRequested();
    20 var plans = configuration.GetSection("PricingTable:Plans").Get<PlanOption[]>() ?? [];
    21 if (plans.Length == 0) return Task.FromResult(VisualDataResult.Empty);
    22
    23 var records = plans.Take(100).Select(plan => new VisualDataRecord(plan.Key, new Dictionary<string, VisualDataValue?>
    24 {
    25 ["name"] = new VisualDataValue.Text(plan.Name),
    26 ["price"] = new VisualDataValue.Money(plan.Amount, plan.Currency),
    27 ["period"] = new VisualDataValue.Text(plan.Period)
    28 })).ToArray();
    29
    30 // Collections return records and leave Values empty.
    31 return Task.FromResult(new VisualDataResult(VisualDataStatus.Success, new Dictionary<string, VisualDataValue?>())
    32 {
    33 Records = records
    34 });
    35 }
    36
    37 public sealed record PlanOption(string Key, string Name, decimal Amount, string Currency, string Period);
    38}

    Record keys (basic, team, business) must start with a lowercase letter and use only lowercase letters, digits and hyphens. Currencies must be three uppercase letters.

  3. 3
    Register it
    csharp
    1using ClientCraft.VisualBuilder.Umbraco.Data;
    2using Umbraco.Cms.Core.Composing;
    3using Umbraco.Cms.Core.DependencyInjection;
    4
    5namespace MySite.Pricing;
    6
    7public sealed class PricingComposer : IComposer
    8{
    9 public void Compose(IUmbracoBuilder builder) => builder.AddVisualDataSource<PricingPlansProvider>();
    10}

    Build and restart the site.

  4. 4
    Add the CollectionOpen the page in the builder and insert a Collection inside a section. Set its Collection source to Pricing plans.
  5. 5
    Design one cardInside Item template, add a Box with three Text blocks. Set each Text block's Text source to Connect data and pick Pricing plans with Plan name, Price and Billing period. Style the Box (padding, border, radius) on the Style tab. The builder previews the first record.
  6. 6
    Design the statesIn When no items are available, add a Text such as "Plans are being updated. Contact us for a quote." In When the source is unavailable, add the same message with a link to your contact page.
  7. 7
    Publish and checkSelect Save and publish and open the public page. Change an amount in configuration, restart, and reload: every page with the table shows the new price.

Result #

One card per plan, in the order your provider returns them. Prices are formatted for the page's culture with their currency code, for example EUR 49.00 on an English page.

Was this article helpful?