Modify pages
Sitefinity CMS allows you to modify the PageNode and the underlying PageData through the code.
When modifying a page, you must perform the following:
- Get the page.
When modifying the page, you must get thePageNodeor thePageData. To modify the title, the HTML title, or the description of the page, you must get and modify thePageDataobject. To modify the URL of the page, you must get thePageNodeobject. For more information about finding a specificPageNodeorPageData, see For developers: Query pages. - Modify the properties.
After you get the page object, you modify the properties. - Save the changes.
Finally, you must save the changes.
Native API
To modify a page using the Native API, you must use the PageManager class.
To modify the HtmlTitle and the Description of a page, perform the following:
- Get the
PageDatawith the specifiedTitleby callingGetPageDataListand filtering based on theTitleproperty. - Modify the
HtmlTitleand theDescriptionproperties. - Save your changes.
Use the following code sample:
C#
using System.Linq;
using Telerik.Sitefinity.GenericContent.Model;
using Telerik.Sitefinity.Modules.Pages;
using Telerik.Sitefinity.Pages.Model;
namespace SitefinityWebApp
{
public class ModifyPages_ModifyPageNativeAPI
{
public void ModifyPageNativeAPI(string pageTitle, string htmlTitle, string description)
{
PageManager pageManager = PageManager.GetManager();
PageData page = pageManager.GetPageDataList()
.Where(pD => (pD.NavigationNode.Title == pageTitle && pD.Status == ContentLifecycleStatus.Live))
.FirstOrDefault();
if (page != null)
{
page.HtmlTitle = htmlTitle;
page.Description = description;
pageManager.SaveChanges();
}
}
}
}
Fluent API
To modify a page using the Fluent API, you must use the page facade.
To modify the HtmlTitle and the Description of a page, perform the following:
- Get the
PageNodeof the page with the specifiedTitle. - Modify the
HtmlTitleand theDescriptionof thePageDataobject. - Save your changes.
Use the following code sample:
C#
using Telerik.Sitefinity;
using Telerik.Sitefinity.GenericContent.Model;
namespace SitefinityWebApp
{
public class ModifyPages_ModifyPageFluentAPI
{
public void ModifyPageFluentAPI(string pageTitle, string htmlTitle, string description)
{
App.WorkWith()
.Pages()
.Where(pN => (pN.Title == pageTitle && pN.GetPageData().Status == ContentLifecycleStatus.Live))
.ForEach(pN =>
{
pN.GetPageData().HtmlTitle = htmlTitle;
pN.GetPageData().Description = description;
}).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.