开发者

Sitecore - Hide Button in Ribbon

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.


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);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜