I have made a custom /sitecore/templates/System/Layout/Renderings/View rendering
called UpdateButton
. I would like to only enable this for certain templates. Currently I am completely hiding it when on an item that isn't the appropriate type by setting this.IsVisible = false
. This hides the icon completely and makes it so the button cannot be clicked.
Is there a way to set it to be disabled like what can be done with a normal command in the query state where the icon is grayed out and the button cannot be clicked?
Button Code:
namespace Common.CustomSitecore.Speak.Controls
{
public class UpdateButton : Sitecore.ExperienceEditor.Speak.Ribbon.Controls.LargeButton.LargeButton
{
public UpdateButton(RenderingParametersResolver renderingParametersResolver) : base(renderingParametersResolver)
{
}
protected override void InitializeControl(RenderingParametersResolver resolver)
{
if(ResolveContentItem()?.TemplateId != "{MyId}")
this.IsVisible = false;
base.InitializeControl(resolver);
}
}
public static class ControlsExtension
{
public static HtmlString UpdateButton(this Sitecore.Mvc.Controls controls, Rendering rendering)
{
Sitecore.Diagnostics.Assert.ArgumentNotNull(controls, "controls");
Sitecore.Diagnostics.Assert.ArgumentNotNull(rendering, "rendering");
var largeButton = new UpdateButton(controls.GetParametersResolver(rendering));
return new HtmlString(largeButton.Render());
}
}
}
Cshtml File:
@using Sitecore.Mvc
@using Common.CustomSitecore.Speak.Controls
@model Sitecore.Mvc.Presentation.RenderingModel
@Html.Sitecore().Controls().UpdateButton(Model.Rendering)
From what I've seen, buttons in core that are disabled at times for the experience editor ribbons still use commands which makes me think this will need to be something custom.