3

We have a requirement where we need to publish component templates to broker database (they are dynamic templates) the fastest and easiest way possible. We need this because we need to get list of all templates via content delivery web service (odata). We want this to be as fastest as possible, not to distract publishing process much (we have about 350 CTs).

Is there some possibility where we can publish JUST the template "metadata" to the broker? We want to decrease rendering per template. Everywhere I look it always require Component and template together that renders output which is then in publish instructions (in transport package xml file).

  • There is a similar scenario for us, where we need to get CT metadata value based on the dynamic component tcm id. Can you please explain in detail how have you achieved the above ? – Bhavesh Malik Feb 5 '18 at 14:21
  • please take a look at my answer related to your question. – Marko Milic Feb 5 '18 at 20:56
  • Or ask a new question... – Nuno Linhares Feb 7 '18 at 15:37
6

You could create a (dummy) Page based on a Page Template which collects and renders the required CT metadata of all CTs (in JSON or XML format).

Publishing the metadata of all CTs can be achieved by publishing that single (dummy) Page. Likewise, retrieving the metadata of all CTs can be achieved by requesting that single Page.

2

I am posting this as answer, and not as comment to your question because its easier this way. What we did is used TOM.NET API during rendering to extract all meta we need about component templates. You can achieve that by using following filter:

 RepositoryItemsFilter filter = new RepositoryItemsFilter(session)
            {
                    ItemTypes = new ItemType[] { ItemType.ComponentTemplate },
                    Recursive = true
            };

Then you can retrieve all templates in publication via following code:

Publication publication = (Publication)engine.GetObject(publicationWebDAV);
XmlElement componentTemplates = publication.GetListItems(filter);
IEnumerable<XElement> componentTemplateXElementList = XDocument.Parse(componentTemplates.OuterXml).Root.Descendants().Where(item => item.Attribute("Type").Value == "32");
foreach (XElement componentTemplateXElement in componentTemplateXElementList)
{
    int componentTemplateId = new TcmUri(componentTemplateXElement.Attribute("ID").Value).ItemId;
    componentTemplates.TryAdd(componentTemplateId.ToString(), componentTemplateXElement.Attribute("Title").Value);
}

After that you can use session to read component template object, do some additional parsing and generate your xml or json containing all relevant data about your templates. They will be published to broker with defined template, so on content delivery side you can always query it. But please make one note: every time you change something about your templates (either create new one, update current one), you will have to republish this custom template to refresh data on content delivery.

  • 1
    I would recommend using publication.GetItems(filter).Cast<ComponentTemplate>() to get a list of ComponentTemplate objects directly, instead of first getting an XML list, serializing it to a string, then parsing it into an XDocument and then obtaining TOM.NET objects for each item. – Rick Pannekoek Feb 6 '18 at 19:54
  • Nice one Rick :) :) :) – Marko Milic Feb 6 '18 at 19:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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