0

we can able to find the Component templates used Pages in the CMS tool but among the results, we need to verify every page and check the page URL.

As per my requirement, we need to get all the page URLs based on CT. Can you please share any code snippets to match the requirement?

1 Answer 1

3

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.