You can override QueryState
method like that:
public override CommandState QueryState(CommandContext context)
{
var item = context.Items[0];
if (item.TemplateID != MyTemplateId)
return CommandState.Hidden;
return base.QueryState(context);
}
EDIT
After OP's question. There is no additional configuration needed. It's just one more method you need to override. So if you copied code from the link you added in your question and wrote your custom code in Execute
method, you need to do the same with QueryState
method:
using Sitecore.Shell.Framework.Commands;
using System;
namespace Sc.Int.MiniBizz.Customaztion
{
class MBCustomButtonImport : Command
{
public override void Execute (CommandContext context)
{
Sitecore.Context.ClientPage.ClientResponse.Alert("Testing my button");
}
public override CommandState QueryState(CommandContext context)
{
var item = context.Items[0];
if (item.TemplateID != MyTemplateId)
return CommandState.Hidden;
return base.QueryState(context);
}
}
}