+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Programatically adding content in placeholder which is defined in template

Programatically adding content in placeholder which is defined in template

1 posts, 0 answered
  1. Mandar
    Mandar avatar
    0 posts
    Registered:
    29 Mar 2017
    10 Apr
    Link to this post

    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.

     

1 posts, 0 answered