Query all pages of a translation
Native API
To get all pages in a particular language, you use the GetPageDataList method. Then, you filter based on the Culture property, the LocalizationStrategy, theNodeType, and theRootNodeId. As a result, you get all pages for the specified language.
Use the following code sample:
C#
using System.Linq;
using System.Threading;
using Telerik.Sitefinity.Modules.Pages;
namespace SitefinityWebApp
{
public class QueryPages_GetAllTranslationsOfPage_NativeAPI
{
public void GetAllTranslationsOfPage()
{
var cultureInfo = new System.Globalization.CultureInfo("cz");
var currentCulture = Thread.CurrentThread.CurrentUICulture;
var ci = System.Globalization.CultureInfo.GetCultureInfo("cz");
var pageManager = PageManager.GetManager();
var pages = pageManager.GetPageDataList().Where(pageData =>
(pageData.Culture == "cz" ||
pageData.NavigationNode.LocalizationStrategy != Telerik.Sitefinity.Localization.LocalizationStrategy.Split) &&
pageData.NavigationNode.NodeType == Telerik.Sitefinity.Pages.Model.NodeType.Standard &&
pageData.NavigationNode.RootNodeId == Telerik.Sitefinity.Abstractions.SiteInitializer.CurrentFrontendRootNodeId)
.Select(x => x.NavigationNode);
var filteredTranslations = pages.ToList();
}
}
}
Fluent API
To get all live pages, you use the plural facade to get all page nodes. Then, you filter based on the NodeType property and the PageData object.
Use the following code sample:
C#
using System.Globalization;
using Telerik.Sitefinity;
namespace SitefinityWebApp
{
public class QueryPages_GetAllTranslationOfPage_FluentAPI
{
public void QueryPages_GetAllTranslationsOfPage_FluentAPI(CultureInfo ci)
{
var childNodes = App.WorkWith()
.Pages()
.LocatedIn(Telerik.Sitefinity.Fluent.Pages.PageLocation.Frontend)
.Where(p => p.GetPageData() != null && p.NodeType == Telerik.Sitefinity.Pages.Model.NodeType.Standard)
.ThatArePublished()
.ThatAreForLanguage(ci)
.Get();
}
}
}
Using Sitemap API
In a multilingual setup, you can query pages from the sitemap only for specific languages. Also, you can get the different translated versions of the same page. To do these, perform the following:
- Set the culture for which you want to query the pages using
CultureRegionclass. - Enumerate the sitemap nodes and get only the
PageSiteNodes. - For each such page node, use
AvailableLanguagesto query its available languages.
Use the following code sample:
C#
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Web;
namespace SitefinityWebApp.Examples
{
public partial class GetPagesFromSitemapInSpecificLanguageExample
{
public void GetPagesFromSitemapInSpecificLanguage(CultureInfo culture)
{
SiteMapProvider pro = SiteMapBase.GetSiteMapProvider(HttpContext.Current.Request.RequestContext);
using (new CultureRegion(culture))
{
SiteMapNodeCollection nodes = pro.GetChildNodes(pro.RootNode);
foreach (SiteMapNode node in nodes)
{
PageSiteNode pageSiteNode = (node as PageSiteNode);
if (pageSiteNode != null)
{
CultureInfo[] availableLanguages = pageSiteNode.AvailableLanguages;
// check available languages for page node. A page node will be returned for pages in specific language even if the an actual page version in that language is not present
}
}
}
}
}
}
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.