More in this section

Forums / General Discussions / How to add a content block item to dynamically created page

How to add a content block item to dynamically created page

4 posts, 0 answered
  1. HuzBlues!
    HuzBlues! avatar
    2 posts
    Registered:
    16 May 2011
    17 May 2011
    Link to this post
    I'd like to add a content block control item to a page I am dynamically creating. How can I do it?

    Telerik.Sitefinity.Modules.Pages.PageManager pManager =
                    new Telerik.Sitefinity.Modules.Pages.PageManager();
                //Guid templateGuid = pManager.GetTemplates().First().Id;             
                var newPageNode = App.WorkWith().Page()
                                         .CreateNewStandardPage(PageLocation.Frontend)
                                         .Do(p =>
                                         {
                                             p.Name = "name";
                                             p.Title = "title";
                                             p.UrlName = "urlName";
                                             p.ShowInNavigation = true;
                                             p.LastModified = DateTime.UtcNow;
                                             p.DateCreated = DateTime.UtcNow;
                                             p.Page.Title = "name";
                                             //set title which appears in page header
                                             p.Page.HtmlTitle = "title";
                                             p.Description = "Some description";
                                         })                                                                                                               
                                         .CheckOut()                                                                          
                                         //.SetTemplateTo(templateGuid)
                                         .Publish()                                     
                                         .SaveChanges();
                SiteMapBase.Cache.Flush();
  2. Victor Velev
    Victor Velev avatar
    1345 posts
    Registered:
    06 Jul 2015
    17 May 2011
    Link to this post
    Hi,

    First you need to set up your template which will be used for the pages that are going to be created. You can either use one of the built in templates or your custom template. For your example I have created a template through the UI called 'test'. Then after you create the page you need to to assign a placeholder for your content block which has been previously initialized. Please refer to the attached code sample, which demonstrates the wanted behaviour.

    Kind regards,
    Victor Velev
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. HuzBlues!
    HuzBlues! avatar
    2 posts
    Registered:
    16 May 2011
    17 May 2011
    Link to this post
    Hi Victor,

    Thanks for assisting me, I am new to the Sitefinity API, so your explanation is helpful. I tried running the test code you provided, but I am running into the following run time error

    Object reference not set to an instance of an object.


    Line 35:             var pageTemplate = pManager.GetTemplates().Where(tm => tm.Title == "test").First();
    Line 36:             Guid templateGuid = pageTemplate.Id;
    Line 37:             PageNode newPageNode = App.WorkWith().Page()
    Line 38:                                      .CreateNewStandardPage(PageLocation.Frontend)
    Line 39:                                      .Do(p =>

    Can you help me determine the cause of the error?
  4. Victor Velev
    Victor Velev avatar
    1345 posts
    Registered:
    06 Jul 2015
    18 May 2011
    Link to this post
    Hello,

    Can you tell me if you have created a custom page template called 'test' ? Are you trying to implement this functionality using new project? Please share with me the steps you took when installing the code to verify the procedure is correct.

    Regards,
    Victor Velev
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
4 posts, 0 answered