-3

I want a list of all component templates, with some of the metadata. What is the easiest way to accomplish that? The Core API?

edit 1, typo. I meant to ask about templates

edit 2, Sorry about that. I'm working with a DD4T site. What I'm after is a list of CT's, along with the view they have been pointed to via metadata. If possible, I thought it would be useful if I could automatically determine if 1) does every DD4T CT actually have a view in our site? and 2) are there any views that don't have a corresponding CT? For now however, I'd be happy with a list of CT's and corresponding views.

2
  • 1
    Your title does not match the question. I've answered based on the title, but can update if the body is the real question Commented Jul 23, 2014 at 20:56
  • You question is still very unclear, You should add information like where you are going to need that list, as that will also have influence on the answer. Also "the easiest way" is not something that can easily be quantified other than by yourself. Rather than asking an opinion based question, you should make your question practical and answerable, please read the FAQ on what question you can and should not ask here. Commented Jul 24, 2014 at 13:19

2 Answers 2

4

I do this:

    private void GetTemplates(SessionAwareCoreServiceClient coreService, IdentifiableObjectData publication)
    {
        RepositoryItemsFilterData templateFilter = GetTemplateFilter(publication);
        XElement templates = coreService.GetListXml(publication.Id, templateFilter);

        foreach (XElement template in templates.Descendants())
        {

            IdentifiableObjectData t = coreService.Read(template.AttributeValueOrEmpty("ID"), null);
        }
    }

    private RepositoryItemsFilterData GetTemplateFilter(IdentifiableObjectData publication)
    {
        RepositoryItemsFilterData templateFilter = new RepositoryItemsFilterData();
        List<ItemType> types = new List<ItemType>();
        types.Add(ItemType.ComponentTemplate);
        templateFilter.Recursive = true;
        templateFilter.BaseColumns = ListBaseColumns.Extended;
        templateFilter.ItemTypes = types.ToArray();
        return templateFilter;
    }

It works well over slow lines and large datasets.

3
  • Thanks! That worked for me. I have a metadata schema linked to my CT's. How do I get to that?
    – Mr Smith
    Commented Jul 24, 2014 at 19:08
  • Cast IdentifiableObjectData to ComponentTemplateData..
    – Raimond
    Commented Jul 24, 2014 at 19:12
  • You're welcome :)
    – Raimond
    Commented Jul 28, 2014 at 8:54
3

Depending on your needs; if you just need a list, count etc, you could use the inbuilt SDL Tridion search functionality to achieve this.

See screenshot below:

enter image description here

4
  • I like your non code approach :D
    – Raimond
    Commented Jul 23, 2014 at 21:03
  • Well of course, you could always use the Search API to do the same thing. :-) Commented Jul 23, 2014 at 21:13
  • Out of the box functionality ;) Commented Jul 23, 2014 at 21:36
  • You could also use TOM.NET, Anguilla or Powershell. Commented Jul 23, 2014 at 22:00

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