2

In tridion java content delivery API, is it possible to get the ComponentTemplate name from the TransportPackage object without giving any tcm id's as parameters

I am using deployer extension which uses tridion content delivery api for java. I have implemented custom processor class. In that we will get package or data of published content as TransportPackage object whenever any content is published. So, I want to extract from it (TransportPackage) the name of ComponentTemplate.

Anyone having any idea about it please let me know.

3

It's impossible to obtain the ComponentTemplate Name from the transport package,because it is not included in the package.

The only thing you can do is obtain the ComponentTemplate uri and then try to get its name, with somehing like this:

public class CustomDeployer extends Module{

private static Logger log = LoggerFactory.getLogger(CustomDeployer.class);

public CustomDeployer(Configuration config, Processor processor)
        throws ConfigurationException {
    super(config, processor);
}

@Override
public void process(TransportPackage data) throws ProcessingException {
    // obtain pages.xml
    ProcessorInstructions instructions = data.getProcessorInstructions();
    MetaData pageMetaInfo = instructions.getMetaData("Pages");
    MetaDataFile pageMeta = data.getMetaData("Pages", pageMetaInfo.getName());

    Iterator<Page> itPage = pageMeta.iterator();
    while (itPage.hasNext()){
        Page page = itPage.next();
        Iterator<ComponentPresentationKey> itCP = page.getComponentPresentationKeys();
        while (itCP.hasNext())
        {
            ComponentPresentationKey key = itCP.next();
            log.debug("component: "+key.getComponentId().getItemId());
            log.debug("template: "+key.getTemplateId().getItemId());
        }
    }

}

But in the presentation side, there is no reference to the Component Template name unless it is published as a dynamic ComponentPresentation.

  • Thanks for solution. As you said, by using ComponentPresentationKey I can get component template name. – user2198112 Apr 9 '14 at 6:11
1

Though the API does not provide a way to the component template name, it is possible to get this info with a bit of help of a TBB when publishing your component presentation (embedded or dynamic). Here is the process:

Render an HTML comment with your CT name at the start of the Component Presentation output. Then in the Deployer extension simply parse it out.

You could also get all fancy and create your own TCDL tag with the CT name, e.g. . You can then create a custom TCDL Tag Handler class which should be available on the Deployer that will catch this tag and give you access to its attributes and body.

  • I didn't try this as you exactly said. But tried something similar to this. I was already getting the component presentation output as xml file in the package. In the deployer extension I parsed that xml file and got the List<ComponentPresentation>, with that I could get component details and component template details. Anyways, thanks for providing possible solution. – user2198112 Apr 9 '14 at 6:15

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.