Create Dynamic Page with with content in Content Blocks in S

Posted by on 07-Dec-2018 05:44

Hi All,

I am trying to create dynamic page with content in content block. Page created with selected template however content block is not properly created even content block not displays title "Content Block" when edit that page. 

When browsing that page in browser it not display any content on the page. Kindly review below code which I used to create page with content.

PageManager manager = PageManager.GetManager();

if (parentPageNodeId == Guid.Empty)
parentPageNodeId = SiteInitializer.CurrentFrontendRootNodeId;

PageNode parent = manager.GetPageNode(parentPageNodeId);
var pageId = Guid.NewGuid();

PageNode pageNode = manager.CreatePage(parent, pageId, Telerik.Sitefinity.Pages.Model.NodeType.Standard);

PageData pageData = pageNode.GetPageData();
pageData.Culture = Thread.CurrentThread.CurrentCulture.ToString();
pageData.HtmlTitle = pageDetail.Title;

pageNode.Name = pageDetail.Title;
pageNode.Description = pageDetail.Title;
pageNode.Title = pageDetail.Title;
pageNode.UrlName = Regex.Replace(pageDetail.Title.ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-");
pageNode.ShowInNavigation = true;
pageNode.DateCreated = DateTime.UtcNow;
pageNode.LastModified = DateTime.UtcNow;
pageNode.ApprovalWorkflowState = "Published";

if (pageDetail.Title.ToLower() == "home")

manager.Provider.SuppressSecurityChecks = true;

// Set Page template
PageTemplate template2 = manager.GetTemplates().Where(a => a.Name == "OneColumnHeaderFooter").FirstOrDefault();
var pageDataId = manager.GetPageNode(pageId).PageId;
var page = manager.EditPage(pageDataId, CultureInfo.CurrentUICulture);
page.TemplateId = template2.Id;
manager.PublishPageDraft(page, CultureInfo.CurrentUICulture);

// Create content Block with content 
ContentBlock cManager = new ContentBlock();
cManager.Html = pageDetail.Content;
cManager.IsShared = false;
cManager.Enabled = true;
cManager.Visible = true;
cManager.ID = "D002";

.CreateNew(cManager, "Content")
.Do(c =>
c.PlaceHolder = GetContentPlaceholderId(template2.Id, "Content", 0);
c.SiblingId = GetLastControlInPlaceHolderInPageId(pageNode.Id, c.PlaceHolder);

Kindly review above code and let me know what I am missing.

Thanks for your help.

All Replies

This thread is closed