How to Read Toolbox Parameters for Sitefinity Widgets

By February 13, 2014Sitefinity

When registering widgets into the Sitefinity toolbox, you’ll notice there is a parameters section. This allows you to add arbitrary key/value pairs of data.

So how do you access these parameters? Through ToolboxConfig of course!

//GET CONFIG
using (var manager = Config.GetManager())
{
    var config = manager.GetSection<ToolboxesConfig>();
 
    //GET PAGE TOOLBOX
    var pageControls = config.Toolboxes["PageControls"];
    var section = pageControls
        .Sections
        .Where<ToolboxSection>(tb => tb.Name == ToolboxesConfig.ContentToolboxSectionName)
        .FirstOrDefault();
 
    //GET CONTROL FROM TOOLBOX IF APPLICABLE
    var controlType = typeof(ContentBlock); //THE TYPE OF WIDGET TO GET
    var control = section.Tools.FirstOrDefault<ToolboxItem>(t => t.Name == controlType.Name);
    if (control != null)
    {
        //PULL OUT PARAMETER FROM TOOLBOX
        var myParam1 = control.Parameters["MyParam1"];
        Response.Write(myParam1);
    }
}

First I am getting a reference to the right toolbox configurations since there is one for pages, layouts, and forms. Next I am querying the toolbox for the widget I want by type. Once I have a reference to the control from the toolbox, I can get the parameters out from there.

Happy Coding!!

The following two tabs change content below.