How to add a content block item to dynamically created page

Posted by Community Admin on 03-Aug-2018 00:34

How to add a content block item to dynamically created page

All Replies

Posted by Community Admin on 17-May-2011 00:00

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();

Posted by Community Admin on 17-May-2011 00:00

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

Posted by Community Admin on 17-May-2011 00:00

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?

Posted by Community Admin on 18-May-2011 00:00

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

This thread is closed