Creating A Widget Of Widgets? Choosing Widget Zone

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
9 years ago
I've been following the link on how to build a plugin. But I noticed the widget plugin asked for

        /// <summary>
        /// Gets widget zones where this widget should be rendered
        /// </summary>
        /// <returns>Widget zones</returns>
        public IList<string> GetWidgetZones()
        {

            return new List<string>() { "home_page_top" };
        }


I want to create a plugin/widget that I can create multiple product sliders in. So I would create a slider, pick the products that I want to show and then specify the widget zone. And then I could create a different one with different products and choose a different widget zone.

But it's asking to specify the widget zone here. So this one widget is sort of multiple widgets. How should I go about this? I'm thinking this is actually not a widget and some other sort of Plugin?

Any pointers appreciated.
9 years ago
leen3o wrote:
I've been following the link on how to build a plugin. But I noticed the widget plugin asked for

        /// <summary>
        /// Gets widget zones where this widget should be rendered
        /// </summary>
        /// <returns>Widget zones</returns>
        public IList<string> GetWidgetZones()
        {

            return new List<string>() { "home_page_top" };
        }


I want to create a plugin/widget that I can create multiple product sliders in. So I would create a slider, pick the products that I want to show and then specify the widget zone. And then I could create a different one with different products and choose a different widget zone.

But it's asking to specify the widget zone here. So this one widget is sort of multiple widgets. How should I go about this? I'm thinking this is actually not a widget and some other sort of Plugin?

Any pointers appreciated.



public void GetDisplayWidgetRoute(string widgetZone, out string actionName, out string controllerName, out RouteValueDictionary routeValues)
        {
            actionName = "PublicInfo";
            controllerName = "WidgetsGoogleAnalytics";
            routeValues = new RouteValueDictionary()
            {
                {"Namespaces", "Nop.Plugin.Widgets.GoogleAnalytics.Controllers"},
                {"area", null},
                {"widgetZone", widgetZone}
            };
        }


You don't need multiple widgets, you just need the widget to display different content based on different zone. And this is already supported. GetDisplayWidgetRoute passes in the current widgetZone that's being rendered. :D
9 years ago
Thanks for your quick reply. It's appreciated. I'm still not following 'How' I would use that to display different content based on different zone?

This is my first plugin attempt. So I'm still getting my head around everything.
9 years ago
Ah. I think I know what you are saying now. In the

ActionResult PublicInfo(string widgetZone)


The current widget zone is actually passed in. So is this method called for ALL widget zones on the page being viewed, and you get the widget name through that 'widgetZone' variable?

If so, what has the

public IList<string> GetWidgetZones()


Got to do with anything?
9 years ago
leen3o wrote:
Ah. I think I know what you are saying now. In the

ActionResult PublicInfo(string widgetZone)


The current widget zone is actually passed in. So is this method called for ALL widget zones on the page being viewed, and you get the widget name through that 'widgetZone' variable?

If so, what has the

public IList<string> GetWidgetZones()


Got to do with anything?


Yes, that's what I mean. PublicInfo() is called each and every time Html.Widget() is called, but different widgetZone is passed in.

GetWidgetZones() returns a list of available widget zones that this plugin can be rendered. You might want to have a look at WidgetService.LoadActiveWidgetsByWidgetZone() for more info.
9 years ago
Awesome thanks. I think I am starting to understand it now.
9 years ago
Were you able to get this to work?  I'm having an issue when I try and dynamically load in a list of available widgets in my plugin.  When I hardcode the widget zones, it works perfectly.

This works:

public IList<string> GetWidgetZones()
{
  return new List<string>() { "home_page_before_footer", "home_page_subfooter_2" };
}


However, this does not work:

public IList<string> GetWidgetZones()
{
  List<string> zones = new List<string>();

  try
  {
    XmlDocument doc = new XmlDocument();
    doc.Load(System.Web.HttpContext.Current.Server.MapPath("/PATH/TO/FILE/zones.xml"));

    XmlNodeList nodes = doc.SelectNodes("/zones/zone");
    foreach (XmlNode node in nodes)
    {
      zones.Add(node.Value);
    }

    if (zones.Count == 0)
    {
      _logger.Warning("No widget zones were loaded.");
    }
  }
  catch (FileNotFoundException fnf)
  {
    _logger.Error("Widget zone configuration file missing.", fnf);
  }
  catch (Exception ex)
  {
    _logger.Error("Error loading the widget zone configuration file.", ex);
  }

  return zones;
}



I have verified that my xml parsing is correct and the function returns back the full list.  However, the PublicInfo method in my widget controller never even fires.  It's not a matter of displaying the incorrect data in the widget zone, it is never executed.  It does fire in the first scenario, when the zone names are hardcoded.

What am I missing? Or where I can look to get more information.  I have a feeling I'm just doing something dumb and it's a simple fix.
6 years ago
wooncherk wrote:
Ah. I think I know what you are saying now. In the

ActionResult PublicInfo(string widgetZone)


The current widget zone is actually passed in. So is this method called for ALL widget zones on the page being viewed, and you get the widget name through that 'widgetZone' variable?

If so, what has the

public IList<string> GetWidgetZones()


Got to do with anything?

Yes, that's what I mean. PublicInfo() is called each and every time Html.Widget() is called, but different widgetZone is passed in.

GetWidgetZones() returns a list of available widget zones that this plugin can be rendered. You might want to have a look at WidgetService.LoadActiveWidgetsByWidgetZone() for more info.


What about the 4.0?
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.