- Kentico Xperience 13
Hiding a widget property in Kentico Xperience 13 Admin
In this post, I will share a tip on how to hide a widget property in the Xperience Admin 13 while it is still available in the backend code.
Considering the following scenario
I need to have a property in a widget. I want to make that property always hidden in the UI. However, I want to be able to work with that property in the backend code. For example, set its value in a view like:
@await Html.Kentico().RenderStandaloneWidgetAsync("jobs.MyWidget", widgetProperties)
Solution
The solution is to add a VisibilityCondition to the property and create a custom visibility condition that always returns false.
Code example
Widget property definition:
using Mynamespace.VisibilityConditions;
using Kentico.Forms.Web.Mvc;
using Kentico.PageBuilder.Web.Mvc;
namespace jobs.kentico.com.Widgets
{
public class BlogPostsWidgetProperties : IWidgetProperties
{
[EditingComponent(IntInputComponent.IDENTIFIER, Label = "Hidden property", Order = 1)]
[VisibilityCondition(typeof(FalseVisibilityCondition))]
public int HiddenProperty { get; set; }
}
}
Visibility Condition definition:
using Kentico.Forms.Web.Mvc;
namespace Mynamespace.VisibilityConditions
{
public class FalseVisibilityCondition : VisibilityCondition
{
public override bool IsVisible()
{
return false;
}
}
}
About the author
Milan Lund is a Full-Stack Web Developer, Solution Architect, and Consultant for Xperience by Kentico projects, working as both a freelancer and a contractor. He specializes in building and maintaining websites using Xperience by Kentico. Milan writes articles based on his project experiences to assist both his future self and other developers.
Find out more