Register new widgets in Sitefinity CMS toolbox
After you implement new widgets, you must register them in the Sitefinity CMS toolbox. You do this by decorating the widget controller class with the ControllerToolboxItem attribute. This attribute defines the following properties of the widget:
|
Property |
Description |
Required |
|
|
The unique developer name of the widget, for example, |
Yes |
|
|
The display name of the widget, visible in the widget toolbox, for example, Content block. |
Yes |
|
|
The unique developer name of the toolbox section, in which you add the widget. This can be an existing section name. To find out the names of existing sections, go to the You can also create a new section and Sitefinity CMS will automatically create toolbox section with the name you have specified. |
Yes |
|
|
The unique name of a Sitefinity module that has to be explicitly activated, so that you can see the widget in the toolbox. You can see the names of modules by navigating to the |
No |
|
|
The unique developer name of the toolbox, in which you register the widget. By default, this is the page controls toolbox
|
No
|
|
|
This property enables you to control the styles of the toolbox item. The widget controller must implement either the |
No |
For more information about new widgets, see Create widgets.
For an example of how to implement a Content Block widget controller, take a look at the GitHub repository.
Sitefinity CMS automatically detects all widget controllers that are decorated with the ControllerToolboxItem attribute and adds the corresponding item to the widget toolbox.
The following sample demonstrates how to decorate the widget controller with the ControllerToolboxItem attribute:
using MyFirstMvcWidget.Mvc.Models;
using System.ComponentModel;
using System.Web.Mvc;
using Telerik.Sitefinity.Mvc;
namespace MyFirstMvcWidget.Mvc.Controllers
{
// The ControllerToolboxItem attribute registers the widget in Sitefinity backend
[ControllerToolboxItem(Name = "MessageWidget", Title = "Message Widget", SectionName = "MvcWidgets")]
public class MessageWidgetController : Controller
{
/// <summary>
/// Gets or sets the message.
/// </summary>
[Category("String Properties")]
public string Message { get; set; }
/// <summary>
/// This is the default Action.
/// </summary>
public ActionResult Index()
{
var model = new MessageWidgetModel();
if (string.IsNullOrEmpty(this.Message))
{
model.Message = "Hello, World!";
}
else
{
model.Message = this.Message;
}
return View("Default", model);
}
}
}