Sitecore - Hide Button in Ribbon

2019-05-06 22:45发布

I created a Contextual Ribbon for a specific content item. I have two buttons that will "promote" or "demote" the item to a certain category (there can only be one in the section).

Is it possible to hide one of the buttons based on the contents state in some sort of code behind? I understand how to link up to the Click event, but I was wondering if there was some sort of load event for the custom ribbon to access.

标签: c# .net sitecore
1条回答
地球回转人心会变
2楼-- · 2019-05-06 23:19

Seems I can use the same class that inherits from Command to override the QueryState method. This is called when the buttons are loaded, and I can do a check there and return a CommandState.Hidden if the button shouldn't be shown

public override CommandState QueryState(CommandContext context)
{
    var item = context.Items[0];

    return item.Fields["Spotlight"].Value == "" ? CommandState.Hidden : base.QueryState(context);
}
查看更多
登录 后发表回答