Register the widget into the system using the RegisterWidget assembly attribute.

Simon Delisle asked on September 25, 2023 21:35

In the Tutorial MVC you have the actual file to be changed when creating the widget NumberWidget from tutorial.

But on the Core version it does not say where to add this code

[assembly: RegisterWidget("LearningKit.Widgets.NumberWidget", "Number selector", typeof(NumberWidgetProperties), customViewName: "~/Components/PageBuilder/Widgets/NumberWidget/_NumberWidget.cshtml")]

I tried to add it in startup.cs or program.cs but it still does not work i cant make the widget appear on my Admin workspace. Can you help me. Thank you!

Correct Answer

Jono Rickard answered on September 26, 2023 02:49

Heya Simon,

It shouldnt matter where you put the RegisterWidget attribute. For widgets that dont have a custom class like this one, I would reccommend making a PageBuilderComponentRegister.cs class in the same folder as Startup.cs, that just contains a big list of these registrations, eg;

PageBuilderComponentRegister.cs

[assembly: RegisterWidget("LearningKit.Widgets.NumberWidget", "Number selector", typeof(NumberWidgetProperties), customViewName: "~/Components/PageBuilder/Widgets/NumberWidget/_NumberWidget.cshtml")]

[assembly: RegisterWidget("LearningKit.Widgets.ExampleWidget1", "Example widget 1", typeof(NumberWidgetProperties), customViewName: "~/Components/PageBuilder/Widgets/ExampleWidget1/_ExampleWidget1.cshtml")]

However, it sounds like there's another reason why it's not working if you're including it in Startup.cs and its not working...

Would you be able to reply with the view where you're expecting the widget to be included? (It should have a <editable-area> tag in it)

1 votesVote for this answer Unmark Correct answer

Recent Answers


Simon Delisle answered on September 26, 2023 17:36

Thank you Jono it works now i gotta find a way to make it work into the admin Edit i get an error 500 when i try to add the widget XD

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.