Programatically adding content in placeholder which is defi

Posted by Community Admin on 04-Aug-2018 09:13

Programatically adding content in placeholder which is defined in template

All Replies

Posted by Community Admin on 10-Apr-2017 00:00

Hi,

Im trying to add content in placeholder that is created inside template.

Here is root template code:

>>>>>>>>>>>>>>

<html><head></head>

<body>
<div class="container">
@Html.Section("top")
@RenderBody()
@Html.Section("bottom")
</div>
</body>
</html>

<<<<<<<<<<<<<<

Here is code of SectionPageTemplate.cshtml template code

>>>>>>>>>>>>>>>>>>

@using Telerik.Sitefinity.Frontend.Mvc.Helpers;
@
    Layout = "~/Mvc/Views/Shared/Root.cshtml";

<h2>Section Page</h2>
<div class="sfPublicWrapper" id="PublicWrapper">
    @Html.SfPlaceHolder("LeftSideBar")
    @Html.SfPlaceHolder("Body")
    @Html.SfPlaceHolder("RightSideBar")
</div>

<<<<<<<<<<<<<<<

In body area of SectionPageTemplate i have added content block widget.

Now based on this template i have created page and indeed i can see editable content block where users should be able add and edit content.

Now i have written api where by i have to fill text in this content block programtically. Hence im using following code to find instance of thsi content block in page which can then be populated:

 

>>>>>>>>>>>>>

           using (PageManager manager = PageManager.GetManager())
           
                PageNode page = manager.GetPageNode(pageId);
                PageData pageData = page.GetPageData();
                var pageDraft = manager.EditPage(pageData.Id);
                IList<PageDraftControl> pageDraftControls = pageDraft.Controls;

//this list is empty
//this should return instance of contentblock widget that has been defined in template

           

<<<<<<<<<<<<

I was expecting that the pageDraftControls List would have instance of contentblock widget control to which i would have simply added .Text = "foo bar" 

What am i doing wrong?

Thanks for your help.

 

This thread is closed