Sitecore - Hide Button in Ribbon

强颜欢笑 提交于 2020-01-02 06:11:17

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/6307773/sitecore-hide-button-in-ribbon

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!