Kraftvaerk.Umbraco.Blockfilter
1.1.3
dotnet add package Kraftvaerk.Umbraco.Blockfilter --version 1.1.3
NuGet\Install-Package Kraftvaerk.Umbraco.Blockfilter -Version 1.1.3
<PackageReference Include="Kraftvaerk.Umbraco.Blockfilter" Version="1.1.3" />
<PackageVersion Include="Kraftvaerk.Umbraco.Blockfilter" Version="1.1.3" />
<PackageReference Include="Kraftvaerk.Umbraco.Blockfilter" />
paket add Kraftvaerk.Umbraco.Blockfilter --version 1.1.3
#r "nuget: Kraftvaerk.Umbraco.Blockfilter, 1.1.3"
#:package Kraftvaerk.Umbraco.Blockfilter@1.1.3
#addin nuget:?package=Kraftvaerk.Umbraco.Blockfilter&version=1.1.3
#tool nuget:?package=Kraftvaerk.Umbraco.Blockfilter&version=1.1.3
Block Filter (by Kraftvaerk)
Block Filter is a simple package that replaces the Block Catalogue Modal in Umbraco with one under our control.
Whenever the modal is opened, a RemodelBlockCatalogueNotification
is sent, allowing you to modify the block catalogue before it is displayed.
Ever wished a block could only be available to certain users or user groups? Only on certain pages? Only if the editor alias is gridContent
? Or maybe only if the logged-in user’s first name is Unicorn?
With Block Filter – and its RemodelBlockCatalogueNotification
handler – the sky’s the limit for deciding who gets to see what… and when.
🏷️ Version support
Block filter is compatible with Umbraco 16.0 and later versions.
🚀 Installation
You can install Block Filter via NuGet:
dotnet add package Kraftvaerk.Umbraco.BlockFilter
🛠️ Usage
To use Block Filter, create a handler for the RemodelBlockCatalogueNotification
.
This handler lets you modify the block catalogue based on your custom logic.
public class YourNotificationHandler : INotificationAsyncHandler<RemodelBlockCatalogueNotification>
{
public YourNotificationHandler()
{
}
public async Task HandleAsync(RemodelBlockCatalogueNotification notification, CancellationToken cancellationToken)
{
// These are only allowed if the user is an admin
var adminAliases = new List<string> { "mySecretBlock" };
if (!notification.Model.User.Groups.Any(g => g.Name == "Administrators"))
{
notification.Model.Blocks = notification.Model.Blocks
.Where(b => !adminAliases.Contains(b.Alias))
.ToList();
}
// "codeBlock" not allowed on the homepage
if (notification.Model.ContentTypeAlias == "home")
{
notification.Model.Blocks = notification.Model.Blocks
.Where(b => b.Alias != "codeBlock")
.ToList();
}
}
}
public class YourComposer : IComposer
{
public void Compose(IUmbracoBuilder builder)
{
builder.AddNotificationAsyncHandler<RemodelBlockCatalogueNotification, YourNotificationHandler>();
}
}
📦 License & Contributing
This package is open source and licensed under the MIT License.
Contributions are welcome!
If you find a bug, want to improve something, or have an idea for a feature, feel free to open an issue or submit a pull request.
— Kaspar
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net9.0
- Umbraco.Cms (>= 16.0.0 && < 17.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.