On the content delivery side I have filtered my components using metadata query, and now I have a list of components that need to be displayed. To get from component to component presentation next step is to choose CT.

As CT Id's will be different across environments, I would like "not to hardcode" id, but instead find CT "by Name".

This is possible through OData

...odata.svc/Templates?$filter=PublicationId eq 5 and Title eq 'Top News'

so the question is, can it be done through API ?

  • It definitely can be done... Can't look it up now, don't we have a TemplateTitleCriteria or something like that?
    – Nuno Linhares
    Mar 16 '15 at 14:21
  • Can't do it. Tried to solve this for the DD4T Smart Target integration. Mar 16 '15 at 14:30
  • possible duplicate of How to get CT Title and custom metadata in DD4T for a DCP? Mar 16 '15 at 14:37
  • Hmm. I can get the list of Component Templates... but not their titles. OK, definitely jumped the gun on this one.
    – Nuno Linhares
    Mar 16 '15 at 15:02
  • @NunoLinhares: After trying couple of possible ways, I got solution to retrieve component templates by their titles. Mar 16 '15 at 15:23

After going through all possible API's, I got a solution to retrieve component template based on component template names.

Mainly you need to use ItemTitleCriteria to retrieving the component templates by names.

Thanks to @NickoliRoussakov for the clue given.

    using (ItemTypeCriteria mItemTypeCriteria = new ItemTypeCriteria(32))
        using (ItemTitleCriteria mItemTitleCriteria = new ItemTitleCriteria("My Component Template"))
            using (PublicationCriteria mPublicationCriteria = new PublicationCriteria(123))
                AndCriteria mTitleCriteria = CriteriaFactory.And(mItemTypeCriteria, mItemTitleCriteria);
                AndCriteria mTemplateCriteria = CriteriaFactory.And(mTitleCriteria, mPublicationCriteria);
                Tridion.ContentDelivery.Meta.IItem[] result = new Query(mTemplateCriteria).ExecuteEntityQuery();

                if (result.Any())
                    Tridion.ContentDelivery.Meta.IItem template = result.FirstOrDefault();
                    String templateTitle = template.Title;
                    String templateId = template.Id.ToString();

Note that above solution might have performance impact. Please test it throughly before using.

Better option would be, by maintaining Component Template ID's in a configuration file with all the required template id's according to the environment and retrieve the component presentations.

  • Yep. Take a look at this Q&A. It is basically the same question: tridion.stackexchange.com/questions/7762/… Mar 16 '15 at 14:38
  • @NickoliRoussakov: Thanks for the clue. To achieve OP criteria, we need to use ItemTitleCriteria Mar 16 '15 at 15:20
  • @Siva, it seems that ItemTitleCriteria is replacing missing TemplateTitleCriteria nicely. This is exactly what I need. Tnx Mar 17 '15 at 9:33

This site is temporarily in read only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .