In this post, I will share a tip on how to hide a widget property in the Xperience Admin 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;
}
}
}
Further reading
all posts- Kentico Xperience
How do we teach university students to use Kentico
From time to time a Kentico partner ask me if I could relocate myself permanently and work for them full time. Unfortunately, I can’t do that because I am a freelancer and I am loy…
- Kentico Xperience
How to add a column to UniGrid in Kentico admin
In this post I will show you the way how to add a column to a UniGrid table in Kentico admin on an example of Product coupons.
- Kentico Xperience
How to install Kentico step by step
The Kentico documentation comprehensively describes all the standard ways how to install Kentico on your machine but in a very general way. So there is no step by step tutoria…