Accessing Widget Name in code

Yowaraj Chhetri asked on August 5, 2020 13:59

Hi Kentico member,

Is there a way to access/get widgetname in a code that we defined while registering a widget.

I am building a functionality where I need to display widget name. I dont want to use widget properties, but get what has been defined while registering that widget.

Thank you in advance

Correct Answer

Dmitry Bastron answered on August 5, 2020 15:39

Hi Yowaraj,

If you are using localization strings to populate widget name and description, then yes, it will be possible. E.g. if your widget is registered like this:

[assembly: RegisterWidget("DancingGoat.HomePage.BannerWidget", typeof(BannerWidgetController), "{$dancinggoatmvc.widget.banner.name$}", Description = "{$dancinggoatmvc.widget.banner.description$}", IconClass = "icon-ribbon")]

Then in the code you can retrieve it like this:

var name = ResHelper.GetString("dancinggoatmvc.widget.banner.name");

Alternatively, if you are hardcoding widget names, I'd suggest using constants for it then and you will be able access constant in widget controller and use it.

1 votesVote for this answer Unmark Correct answer

Recent Answers


Yowaraj Chhetri answered on August 6, 2020 06:36

Thank you Dmitry,

I was looking for something dynamically getting it. However, using localization string can be handy. But I'll prefer constants for my case.

Thank you again.

0 votesVote for this answer Mark as a Correct answer

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