0

I'm trying to create a new widget called "Image Summary Section". I'm at the very beginning stages and I'm just trying to get the widget to appear in the list of widgets when adding widgets to the page. Instead, I just get existing widgets that I didn't create:

Screenshot of Visual Studio and Browser for Kentico Widget Attempt

You can see that I've created a class that implements IWidgetProperties and that I've called RegisterWidget for it. I've also created _ImageSummarySection.cshtml (though, I wouldn't expect that to be necessary just for the widget to appear in the widget selection dialog).

The top solution is for the MVC website, and the bottom solution is for the Kentico CMS. Both are running, and the browser shown is the Kentico CMS (I'm trying to add my new widget in this screenshot, but it's not in the list of widgets).

Any idea of what I'm doing wrong? How can I get my widget to appear in the list of widgets?

Additional information:

.

.

.

.

.

.

EDIT:

I just watched this video, hoping it would provide insight: https://www.youtube.com/watch?v=ljQO9on5lLM

It was more basic than I anticipated, but I did notice these two frames:

Six Widgets

Note that it shows six available widgets to select from.

And then there was this frame:

Two Widgets

It shows only two available widgets.

From that, I infer that sections may have some feature that allows developers to constrain which widgets are allowed in them. Is there perhaps something I need to do in order to allow my widgets to appear as options in the default section (the one shown below)?

Default Section

.

.

.

.

.

.

EDIT #2:

I researched widget constraints a bit and found this: https://docs.kentico.com/k12/developing-websites/page-builder-development/creating-pages-with-editable-areas-in-mvc

Specifically the section titled "Limiting widgets allowed in an editable area", which says the following:

Limiting Widgets

Since my view is not passing a parameter with a whitelist of widgets, all widgets should (in theory) be allowed:

@* Index.cshtml *@
@using Kentico.PageBuilder.Web.Mvc
@using Kentico.Web.Mvc

<h1>Rhythm Agency</h1>

@Html.Kentico().EditableArea("main")

So there goes that theory. I'm still at a loss as to why my new widget isn't appearing as an option when adding new widgets to the page.

Nicholas Westby
  • 1,109
  • 13
  • 32
  • This question is not getting a great response, so I created a new and improved question that shows the latest and greatest changes I've made and new information that I have: https://stackoverflow.com/questions/62959744/how-to-create-an-mvc-widget-in-kentico-12-page-builder – Nicholas Westby Jul 17 '20 at 18:21

2 Answers2

1

For the controller and widget to be recognized you need to put your controller in the '/Controllers' folder. I have my widget controllers located in the '/Controllers/Widgets' folder.

I had issues which included not having added the suffix 'Controller' in the class name and issues with the widget controller not being in the '/Controllers' folder.

Also you aren't working in an seperate project? Because this would need you to use the following in the 'AssemblyInfo.cs'

using CMS;
[assembly: AssemblyDiscoverable]

And make sure you have enabled the page builder feature in your kentico project. For example:

protected void Application_Start()
{
    ...

    // Gets the ApplicationBuilder instance
    // Allows you to enable and configure Kentico MVC features
    ApplicationBuilder builder = ApplicationBuilder.Current;

    // Enables the preview feature
    builder.UsePreview();

    // Enables the page builder feature
    builder.UsePageBuilder();

    ...
}
A. van Hugten
  • 715
  • 5
  • 16
  • Thanks! For those curious, my issue was that I was missing AssemblyDiscoverable. It doesn't really matter which folder/namespace the controller is in (though, I have seen issues with some systems in which the "Controller" suffix in the class name is necessary). – Nicholas Westby Jul 19 '20 at 16:06
0

You're almost there. You need to create another class and register your widgets in the App_Start folder. Check out the documentation here on that. It's the section on widget registration. Be sure to enable Page builder as well.

*** Updated ***

Based on your update and not being able to see the image well on my mobile device, I was able to see you're defining/registering your widget in your Properties model. This needs to be done in the Controller. See the example below.

\Models\Widgets\JobListingWidgetProperties.cs

namespace NameSpace.Models.Widgets.JobListingWidget
{
    public class JobListingWidgetProperties : IWidgetProperties
    {
        // property definitions here
    }
}

\Models\Widgets\JobListingModelView.cs

namespace NameSpace.Models.Widgets.JobListingWidget
{
    public class JobListingWidgetViewModel
    {
        // properties here
    }
}

\Controllers\Widgets\JobListingWidgetController.cs

[assembly: RegisterWidget("NameSpace.Widgets.JobListingWidget", typeof(JobListingWidgetController), "Job Listing Widget", Description = "Displays a listing of jobs for a given path", IconClass = "icon-heartshake")]

namespace NameSpace.Controllers.Widgets
{
    public class JobListingWidgetController : WidgetController<JobListingWidgetProperties>
    {
        public ActionResult Index()
        {
            // code here
        }
    }
}
Brenden Kehren
  • 5,919
  • 16
  • 27
  • Neither suggestion is helpful, I'm afraid. I circled a portion of the screenshot showing that I registered the widget (it doesn't need to be in the `App_Start` folder, as that is just a convention (note this is a web application project, not a website project). Also, the screenshot shows I'm using page builder, so it must be enabled already. – Nicholas Westby Jul 17 '20 at 15:28
  • See the updated answer, looks like you're defining/registering the widget in the property class and not the controller like it should be. – Brenden Kehren Jul 17 '20 at 17:16
  • The controller is optional, according to the training and documentation and Dancing Goat samples. However, I created a controller and renamed the widget for good measure (in case "Section" is a reserved word), and that didn't help. – Nicholas Westby Jul 17 '20 at 17:36
  • I created a new question to show my updates so we can start fresh: https://stackoverflow.com/questions/62959744/how-to-create-an-mvc-widget-in-kentico-12-page-builder – Nicholas Westby Jul 17 '20 at 18:21
  • Ok you got me there, yes the controller is optional. BUT if you don't have a controller, then you need to initialize that widget as I mentioned in my initial response using a separate class. While placing it in the properties class should work, I'd follow what Kentico is recommending. It works every time for us without issue. https://docs.kentico.com/k12sp/developing-websites/page-builder-development/developing-widgets-in-mvc/example-developing-a-widget-in-mvc – Brenden Kehren Jul 17 '20 at 19:30
  • As I stated on the other question, adding the controller did not help. Also, adding the assembly attribute in another file is a stylistic choice, not one that would prevent it from working. Give it a shot on one of your projects; see if adding the assembly attribute in the properties class prevents it from working. I bet you it would work fine (assuming your widget is already working). – Nicholas Westby Jul 17 '20 at 20:00
  • FYI, I moved the widget registration assembly attribute to a class in the `App_Start` folder, and that didn't help, as expected. – Nicholas Westby Jul 17 '20 at 20:41
  • I'm assuming you're rebuilding your solution after you make the changes. Just have to check. – Brenden Kehren Jul 18 '20 at 05:45