Is there a way to get the widgets on a page programmatically?

Kentico Dev asked on February 22, 2020 01:42

For example, in a controller action, I load my Home page node. The Home page has PageBuilder enabled and the content editor has add a couple Rich Text Editor widgets and an Image widget.

I want to be able loop through all widgets on the page, looking just for Rich Text widgets, and then extract the content of those widgets and also get the total number of widgets on the page.

Is that possible?

Correct Answer

Mikhail Dervel answered on February 23, 2020 09:33

Hi Kentico Dev!

You can get JSON with your page widgets : var docCultureInfo = DocumentCultureDataInfoProvider.GetDocumentCultureInfo(homePage.DocumentID); var widgetsJson = docCultureInfo.DocumentPageBuilderWidgets

And then with JObject turn this string into a model and count all widgets

2 votesVote for this answer Unmark Correct answer

Recent Answers

Kentico Dev answered on February 24, 2020 16:04

Yes, that is what I was looking for, thanks!

0 votesVote for this answer Mark as a Correct answer

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