# Query pages by template

## Native API 

To get pages by a specified template, perform the following:

1. Get an instance of the `PageManager` object.
2. Get an instance of the specified template.
3. To get the pages using this template, call the `Pages` extension method of the `PageTemplate` instance. This extension method is located in the `Telerik.Sitefinity.Modules.Pages` namespace.

Use the following code sample:

```C#
using System;
using System.Linq;
using Telerik.Sitefinity.GenericContent.Model;
using Telerik.Sitefinity.Modules.Pages;
using Telerik.Sitefinity.Pages.Model;

namespace SitefinityWebApp
{
    public class QueryPages_GetPagesByTemplate_NativeAPI
    {
        public static IQueryable<PageData> GetPagesByTemplateNativeAPI(Guid templateId)
        {
            PageManager pageManager = PageManager.GetManager();

            PageTemplate template = pageManager.GetTemplate(templateId);

            return template.Pages().Where(p => p.Status == ContentLifecycleStatus.Live);
        }
    }
}
```

## Fluent API

To get the pages that use a specified template you must get the plural facade for the pages. Then filter the pages by the ID of the specified template and their status.

To get the query, call the `Get` method of the facade in the following way:

```C#
using System;
using System.Linq;
using Telerik.Sitefinity;
using Telerik.Sitefinity.GenericContent.Model;
using Telerik.Sitefinity.Pages.Model;

namespace SitefinityWebApp
{
    public class QuesryPages_GetPagesByTemplate_FluentAPI
    {
        public static IQueryable<PageData> GetPagesByTemplateFluentAPI(Guid templateId)
        {
            return App.WorkWith().Pages().Where(p => p.GetPageData() != null && p.GetPageData().Template.Id == templateId && p.GetPageData().Status == ContentLifecycleStatus.Live).Get().Select(p => p.GetPageData(null));
        }
    }
}
```
