Create a page with a Blog posts widget
To create a standard page with a Blog posts widget added on it, perform the following:
- Create a standard Sitefinity CMS page.
Perform procedure For developers: Create a page with the native API. - Edit the page to add the Blog posts widget.
You do this using theEditPagemethod of thePageManagerin the following way:SuppressSecurityChecksof the page provider.- Get the page node by ID.
- Call the
EditPagemethod.
- Create a new Blog post widget and add it to the page.
Blog posts widget is represented by theBlogPostViewclass. Perform the following:- Create an object of the
BlogPostViewclass. - Add the Blog posts widget control to the page draft and set its properties.
- Create an object of the
- Publish page draft and save changes
Use thePublishPageDraftmethod ofPageManagerand callSaveChangesto finalize the creation of the page.
EXAMPLE: In the following code example, the
CreatePageWithBlogPostWidgetmethod creates a new standard page and adds the Blog posts widget on it:
C#
using System;
using System.Text.RegularExpressions;
using Telerik.Sitefinity.Abstractions;
using Telerik.Sitefinity.Modules.Pages;
using Telerik.Sitefinity.Pages.Model;
using Telerik.Sitefinity.Services;
namespace Telerik.Sitefinity.Documentation.CodeSnippets.DevGuide.SitefinityEssentials.Pages
{
public partial class PagesSnippets
{
public void CreatePageWithBlogPostWidget(string pageName)
{
//creates a standard page
PageManager pageManager = PageManager.GetManager();
var parentPageNodeId = SiteInitializer.CurrentFrontendRootNodeId;
PageNode parent = pageManager.GetPageNode(parentPageNodeId);
var pageId = Guid.NewGuid();
PageNode pageNode = pageManager.CreatePage(parent, pageId, NodeType.Standard);
PageData pageData = pageNode.GetPageData();
pageData.HtmlTitle = pageName;
pageNode.Name = pageName;
pageNode.Description = pageName;
pageNode.Title = pageName;
pageNode.ShowInNavigation = true;
pageNode.ApprovalWorkflowState = "Published";
pageManager.SaveChanges();
//adds the blog post widget
pageManager.Provider.SuppressSecurityChecks = true;
var pageDataId = pageManager.GetPageNode(pageId).PageId;
var page = pageManager.EditPage(pageDataId, culture);
var blogsWidget = new Telerik.Sitefinity.Modules.Blogs.Web.UI.BlogPostView();
var blogsWidgetControl = pageManager.CreateControl<PageDraftControl>(blogsWidget, "Body");
blogsWidgetControl.Caption = "BlogPostWidget";
pageManager.SetControlDefaultPermissions(blogsWidgetControl);
page.Controls.Add(blogsWidgetControl);
//publishes draft page
pageManager.PublishPageDraft(page, culture);
pageManager.SaveChanges();
}
}
}
Want to learn more?
Enhance your Sitefinity skills by enrolling in free training sessions. Become Sitefinity certified through Progress Education Community to strengthen your professional credentials.
Get started with Integration Hub | Sitefinity Cloud
This free lesson teaches administrators, marketers, and other business professionals how to use Sitefinity Integration Hub to create automated workflows between Sitefinity and other business systems.
Web Security for Sitefinity Administrators
This free lesson teaches administrators the basics about protecting your Sitefinity instance and your sites from external threats. Configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.
Foundations of Sitefinity ASP.NET Core Development
The free on-demand video course teaches developers how to use Sitefinity ASP.NET Core and take advantage of its decoupled architecture and modern development model.