How to write a Widget

Introduction

A widget is nothing but a plugin that inherits from IWidget so it has to implement the method GetWidgetZones and GetDisplayWidgetRoute. You might decide to develop a widget when you need to display one or more public views in the frontend of a shop. With a widget you are able to customize the output of the frontend and inject the content of your widget whereever you want by rendering it into the desired WidgetZone (for more information about widget zones read the topic Widget Zones).

If you are not familiar with developing plugins for SmartStore.NET please also have look at the tutorial How to write a Plugin.

GetWidgetZones

In this method you enter the widgetzones where you want your widget to be rendered.

public IList<string> GetWidgetZones()
{
	return new List<string>() { "head_html_tag" };
}

 

GetDisplayWidgetRoute

In this method you define the route that gets called when your widget should be rendered.

public void GetDisplayWidgetRoute(string widgetZone, object model, int storeId, out string actionName, out string controllerName, out RouteValueDictionary routeValues)
{
     actionName = "PublicInfo";
     controllerName = "MyWidgetController";
     routeValues = new RouteValueDictionary()
     {
         {"area", "MyCompanyNamespace.MyWidget"},
         {"widgetZone", widgetZone}
     };
}