To retrieve all the page URLs based on a specific Component Template in Tridion Sites using the Core Service, you'll need to perform the following steps:
1. Connect to the Core Service:
Establish a connection to the Core Service using the appropriate credentials. This typically involves creating an instance of SessionAwareCoreServiceClient and providing the necessary authentication details.
using (var client = new SessionAwareCoreServiceClient("netTcp_2013"))
{
// Authenticate and establish a session
client.Impersonate("username", "password");
// Your code goes here
}
2. Retrieve Component Template Information:
Get the Component Template based on its title or WebDAV URL.
var componentTemplateId = "tcm:1-2-32"; // Replace with your Component Template TCM URI
var componentTemplate = client.Read(componentTemplateId, new ReadOptions()) as ComponentTemplateData;
3. Retrieve Pages Using the Component Template:
Once you have the Component Template, you can use it to find associated Pages. You'll need to construct a UsingItemsFilterData to filter Pages based on the Component Template.
var filter = new UsingItemsFilterData
{
ItemTypes = new[] { ItemType.Page },
InRepository = new LinkToRepositoryData { IdRef = componentTemplate.Id },
};
var pages = client.GetList(componentTemplate.Id, filter) ?? new IdentifiableObjectData[] { };
4. Extract URLs from Page Information:
Iterate through the list of Pages to extract their URLs.
foreach (var page in pages)
{
var pageData = client.Read(page.Id, new ReadOptions()) as PageData;
if (pageData != null)
{
var pageUrl = pageData.PublishLocationUrl;
// Process or output the page URL as needed
}
}
I hope it helps.