Modifying pages
Sitefinity allows you to modify the page node and the underlying page data.
When modifying a page, you must perform the following:
-
Get the page node or data.
When modifying the page, first, you must get the page node or data. To modify the title, html title and description of the page in the UI, you must get and modify the PageData object. To modify the url of the page, you must get the PageNode object. For more information about finding a specific page node and data, see Querying pages.
-
Modify the properties.
After you get the page node or data, you modify the properties.
-
Save the changes.
Finally, you must save the changes.
To modify a page you can use the Native API or the Fluent API.
To modify a page using the Native API, you must use the PageManager class. For more information, see Modifying a page using Native API.
To modify a page using the Fluent API, you must use the page facade. For more information, see Modifying a page using Fluent API.
Modifying a page using Native API
The following example modifies the HtmlTitle and Description of a specific page:
public void ModifyPageNativeAPI(string pageTitle, string htmlTitle, string description)
{
PageManager pageManager = PageManager.GetManager();
PageData page = pageManager.GetPageDataList()
.Where(pD => (pD.Title == pageTitle && pD.Status == ContentLifecycleStatus.Live))
.FirstOrDefault();
if (page != null)
{
page.HtmlTitle = htmlTitle;
page.Description = description;
pageManager.SaveChanges();
}
}
First, you get the page data with the specified Title by calling GetPageDataList and filter based on the Title property. Then, you modify the HtmlTitle and the Description properties. Finally, you save the changes.
Modifying a page using Fluent API
The following example modifies the HtmlTitle and Description of a specific page:
public void ModifyPageFluentAPI(string pageTitle, string htmlTitle, string description)
{
App.WorkWith()
.Pages()
.Where(pN => (pN.Page != null && pN.Page.Title == pageTitle && pN.Page.Status == ContentLifecycleStatus.Live))
.ForEach(pN =>
{
pN.Page.HtmlTitle = htmlTitle;
pN.Page.Description = description;
}).SaveChanges();
}
First, you get the page node of the page with the specified Title. Then, you modify the HtmlTitle and the Description of the PageData object. Finally, you save the changes.