Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I access the Component Template ID from within my Component DWT?

Tags:

tridion

In the HTML template for my Component I need to write out the TCM URI of the Component Template:

<!-- Start Component Presentation: {"ComponentID" : "@@Component.ID@@",
                        "ComponentTemplateID" : "@@ComponentTemplate.ID@@" } -->

But unfortunately ComponentTemplate.ID doesn't exist.

How can I access the Component Template ID from within my Component DWT?

like image 355
Frank van Puffelen Avatar asked Mar 30 '12 07:03

Frank van Puffelen


2 Answers

I'm afraid you'll have to write a C# TBB (fragment or assembly):

TcmUri templateId = engine.PublishingContext.ResolvedItem.Template.Id;
if (templateId.ItemType == ItemType.ComponentTemplate) {
    Item item = package.CreateStringItem(ContentType.Text, templateId.ToString());
    package.PushItem("ComponentTemplateID", item);
}

You can only access the ComponentTemplate.ID from within a Page DWT layout...

like image 70
Mihai Cădariu Avatar answered Oct 15 '22 16:10

Mihai Cădariu


Add a "ComponentTemplateID" parameter to the Template Invocation in the compound template. You can then access this in the same way as package variables.

like image 1
Dominic Cronin Avatar answered Oct 15 '22 16:10

Dominic Cronin