Programmatically adding widgets to a structured page

Massimo Della Calce asked on October 27, 2020 17:13

From what I understand, widgets are the minimal unit in Kentico MVC to set up variants of content for context marketing and A/B testing. A landing page is an example of a content type to apply these components to. Does this mean that I can't do context marketing on a structured page? My need, in this specific case, is to programmatically create structured pages and set their fields. For some sections of the aforementioned pages I would like to add widgets in the same way (programmatically) by setting their values ​​(texts, images, videos, ...). How is it possible to reach the goal? Is there any example I can use?

Recent Answers


Dmitry Bastron answered on October 29, 2020 11:26

Hi Massimo,

You can add and remove A/B test variants programmatically, please see API examples here. But there is no public API to add widgets unfortunately, which makes A/B test variants API pretty useless I agree.

If you really need to deal with it, to hack around this, when creating pages and variants you may work directly with JSON stored in DocumentPageBuilderWidgets column of CMS_Document table: it contains all widgets and variants data. But there is no documentation or guidance to do so.

1 votesVote for this answer Mark as a Correct answer

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