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
    29 Mar 2017
    10 Apr
    Link to this post


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

    Here is root template code:



    <div class="container">


    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">


    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