Filter Records in Page selector by Templates

Posted by dexter.leow on 16-May-2019 09:19

Hi, I would only like to show my pages that are built using Standard Templates, and not the rest of the templates. 
Can someone kindly guide me on how this can be done please?

Appreciate any help, thanks much

All Replies

Posted by jread on 17-May-2019 18:33

You can query pages by page template id using this article: 

https://www.progress.com/documentation/sitefinity-cms/for-developers-query-pages-by-template

Code:

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);
        }
    }

You can get the page template by title by following this article:
https://www.progress.com/documentation/sitefinity-cms/for-developers-query-page-templates#finding-a-page-template-by-title

Code:

        public static PageTemplate FindPageTemplateByTitle(string title)
        {
            PageManager pageManager = PageManager.GetManager();
            PageTemplate template = pageManager.GetTemplates().Where(t => t.Title == title).FirstOrDefault();
            return template;
        }


This thread is closed