How to retrieve pages
Hello,
I have one content type in which i have created one page selector field. I have total 10+ different type of page template Now i want to retrieve Url, Page Template Type and Page Name of the pages that has been selected by author for these field using page selector component.
Please suggest me if kentico has any support for that or i have to create custom logic for achieve above functionality. Any Sample code would be appreciated.
Environment
Xperience by Kentico version: [30.5.2]
.NET version: [8]
Answers
I would always recommend using the combined content selector (which uses the Pages and reusable content field data type) over the Page selector (which uses the Pages field data type). The combined content selector will continue to get the most new features and UX improvements and covers almost all of the same functionality of the Page selector.
The combined content selector makes querying much simpler because it models your C# classes as having a collection of content items instead of a collection of references (Guid values) to other content items. This means you can the WithLinkedItems content query API (using the new IContentRetriever or ContentItemQueryBuilder) to perform 1 query instead of 2.
Both querying approaches (
IContentRetriever
andContentItemQueryBuilder
) have documentation explaining which APIs you need call to ensure you can retrieve the page URL for any query results. But, in both cases you would use the IWebPageUrlRetriever.Why do you want to retrieve the page template of the page? This is an internal implementation detail and cannot be used in your code in website channels.
The "page name" is for internal use (within the Xperience administration UI). If you want a publicly visible page name or title, create your own custom field in your content type or in a reusable field schema (RFS) which you can apply to multiple content types.
The Kentico Community Portal uses a
IBasicItem
RFS to ensure all web pages have a title and short description field.
To answer this question, you have to login first.