Company logo
April 21, 2022

Programmatically add category

Jared Luxenberg's avatar

We've added new SDK methods to make it possible to control the behavior of CommandBar categories via code. It's always been possible to add commands via code (though we still recommend the Editor for most situations). However, when creating programmatic commands it was still necessary to use the Editor to create categories to which those programmatic commands could be linked.

Now, you can simply specify a category string in CommandBar.addCommand, and command will create a category corresponding to that string -- making the programatic command "just work" without any corresponding config changes in the Editor. The programmatic category's settings can be adjusted using CommandBar.setCategoryConfig.

Code example

// Most common: define a new category inside of addCommand window.CommandBar.addCommand({ text: 'Go to Home', name: 'go_to_page_home', template: { type: 'link', value: '/home', operation: 'self' // how should the page open }, category: 'Navigation', });

// Less common: define a new category before using it window.CommandBar.setCategoryConfig( "Navigation", { search_tab_enabled: true } );

window.CommandBar.addCommand({ .... category: 'Navigation', ...