https://github.com/abjerner/limbo.umbraco.blocklist
Extended block list editor for Umbraco.
https://github.com/abjerner/limbo.umbraco.blocklist
block-list csharp dotnet limbo package skybrud umbraco umbraco-cms umbraco-package umbraco-packages umbraco-v10 umbraco-v11 umbraco-v12 umbraco-v8 umbraco-v9
Last synced: 4 months ago
JSON representation
Extended block list editor for Umbraco.
- Host: GitHub
- URL: https://github.com/abjerner/limbo.umbraco.blocklist
- Owner: abjerner
- License: mit
- Created: 2022-01-22T18:24:58.000Z (over 4 years ago)
- Default Branch: v13/main
- Last Pushed: 2024-11-25T12:09:39.000Z (over 1 year ago)
- Last Synced: 2025-07-22T08:04:02.243Z (11 months ago)
- Topics: block-list, csharp, dotnet, limbo, package, skybrud, umbraco, umbraco-cms, umbraco-package, umbraco-packages, umbraco-v10, umbraco-v11, umbraco-v12, umbraco-v8, umbraco-v9
- Language: C#
- Homepage:
- Size: 885 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Limbo Block List
[](https://github.com/abjerner/Limbo.Umbraco.BlockList/blob/v13/main/LICENSE.md)
[](https://www.nuget.org/packages/Limbo.Umbraco.BlockList)
[](https://www.nuget.org/packages/Limbo.Umbraco.BlockList)
[](https://packages.limbo.works/limbo.umbraco.blocklist/)
[](https://marketplace.umbraco.com/package/limbo.umbraco.blocklist)
This package extends the default block list property editor in Umbraco, making it possible to control the CLR type returned by our version of the block list property editor.
License:
MIT License
Umbraco:
Umbraco 13
(and Umbraco 10-12, Umbraco 9 and Umbraco 8)
Target Framework:
.NET 8
(and .NET 6, .NET 5 and .NET 4.7.2)
## But why?
The default block list property editor exposes the value as an instance of `BlockListModel` representing the invividual blocks as they are added by users in the backoffice.
If you wish to interpret the `BlockListModel` a bit before rendering the block list on the website, there is a few different ways to go about this. With this package, you can select a *type converter* which is then used for converting `BlockListModel` to a desired type.
For us at [**@limbo-works**](https://github.com/limbo-works), we find this particular usefull as we can use a *type converter* to control the output for our headless API, thereby better being able to tailor the output for our frontenders.
## Installation
### Umbraco 13
The package is only available via [**NuGet**](https://www.nuget.org/packages/Limbo.Umbraco.BlockList/13.0.3). To install the package, you can use either .NET CLI:
```
dotnet add package Limbo.Umbraco.BlockList --version 13.0.3
```
or the NuGet Package Manager:
```
Install-Package Limbo.Umbraco.BlockList -Version 13.0.3
```
### Other versions of Umbraco
- ~~[**v3/main**](https://github.com/abjerner/Limbo.Umbraco.BlockList/tree/v3/main) Umbraco 10-12~~ (EOL)
- ~~[**v2/main**](https://github.com/abjerner/Limbo.Umbraco.BlockList/tree/v2/main) Umbraco 9~~ (EOL)
- ~~[**v1/main**](https://github.com/abjerner/Limbo.Umbraco.BlockList/tree/v1/main) Umbraco 8~~ (EOL)
## Examples
To create your custom type converter, you can implement the `IBlockListTypeConverter` interface. In the example below, the type converter will return a flat array of `BlockItem` representing the individual block list items - or if the maximum amount of blocks it set to 1, an instance `BlockList`:
```csharp
using System;
using System.Linq;
using Limbo.Umbraco.BlockList.Converters;
using Limbo.Umbraco.BlockList.PropertyEditors;
using Umbraco.Cms.Core.Models.Blocks;
using Umbraco.Cms.Core.Models.PublishedContent;
namespace UmbracoTests.BlockList {
public class BlockListTypeConverter : IBlockListTypeConverter {
public string Name => "Block Item Converter";
public Type GetType(IPublishedPropertyType propertyType, LimboBlockListConfiguration config) {
return config.IsSinglePicker ? typeof(BlockItem) : typeof(IReadOnlyList);
}
public object? Convert(IPublishedElement owner, IPublishedPropertyType propertyType, BlockListModel? source, LimboBlockListConfiguration config) {
if (source == null) return config.IsSinglePicker ? null : Array.Empty();
if (!config.IsSinglePicker) return source.Select(x => new BlockItem(x)).ToArray();
BlockListItem? first = source.FirstOrDefault();
return first == null ? null : new BlockItem(first);
}
}
}
```
```csharp
using System;
using Umbraco.Cms.Core.Models.Blocks;
using Umbraco.Extensions;
namespace UmbracoTests.BlockList {
public class BlockItem {
public Guid ContentKey { get; }
public string Type { get; }
public IPublishedElement Content { get; }
public BlockItem(BlockListItem blockListItem) {
ContentKey = blockListItem.Content.Key;
Type = blockListItem.Content.ContentType.Alias;
Content = blockListItem.Content;
}
}
}
```
By creating your own class implementing the `IBlockListTypeConverter` interface, it will show up for the **Type Converter** option on the data type:
