Inline widget not rendered when added through API

Tomasz Sikora asked on January 5, 2018 17:00

I'm adding an inline widget through api like this:

var html= $"<object codetype=\"CMSInlineControl\" style=\"display: none\" type=\"widget\"><param name=\"closeformtext\" value=\"{closeform}\" /><param name=\"bizformformid\" ......

podTreeNode.SetValue("PodHTML", html);

and after treeNode.Update(); when I look at the live page where widget should be, I got <object> and <param> elements rendered in site's markup.

But! After I'll go to this page with widget I already added through API and click SAVE on Content tab: Image Text

I'll get my widget rendered on live site.

Just by clicking save and not doing anything, my widget started to work. How can I make this working through API without need to go to specific page and resave it by clicking save button in admin panel?

Recent Answers

Peter Mogilnitski answered on January 5, 2018 19:10 (last edited on January 5, 2018 22:53)

Your markup seem OK:

<object codetype="CMSInlineControl" style="display: none" type="widget">
  <param name="..." value="..." />

I would assume that there is a problem with encoding or some other string issue. What I would do is to look at directly in the DB on CMS_Document.DocumentWebParts field or your field of your document type where widget is saved as xml (depends on where you use your widget).

  1. Check the field in SQL after the API code is executed
  2. And then after you save it in admin interface and compare the differences.
0 votesVote for this answer Mark as a Correct answer

Tomasz Sikora answered on January 8, 2018 10:35 (last edited on January 8, 2018 16:42)

I've checked that in database and it looks like this: When I add widget through api with <object> syntax, the DB record in custom table that represents my page type with this HTML field looks like this:

<object codetype="CMSInlineControl" ...

But when I go to admin panel and click save, then this record looks like this:

{^widget|(closeformtext) ...

The same goes for CI files when they are generated

0 votesVote for this answer Mark as a Correct answer

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