When writing a deployer extension (for the first time!), is it possible to load the file contents of a component presentation?

So my instructions contain the following:

<Section Type="ComponentPresentations" Name="ComponentPresentations">
<ComponentPresentation Name="tcm_70-18142_tcm_70-17937-32" TemplateId="tcm:70-17937-32" ComponentId="tcm:70-18142"/>

I have logic already to find the component presentation I need using getFileItems() but this only returns an iterator of ComponentPresentationKeys.

I'm not sure exactly how to use a ComponentPresentationKey to load my component presentation so I can get to the rendered output?

When you need to access published content as I do, is it actually better to override an existing module?

If I extended ComponentPresentationDeploy I think the processComponentPresentation method would give me access to published contents, but I need to know the schema of the component in order to trigger my custom business logic, but this isn't available if you override in this way.

As my output is just Xml, I could add schema info in here, but I'd have to load every presentation as an Xml doc and check the schema - when I know some can be ignored, hence my attempt to do this by not overriding an existing module.


I've had more success moving to overriding ComponentPresentationDeploy (as Jon describes below) as this way the component presentation package file is provided as part of the overidden method signature, removing the need for me to load this file manually (I suspect then that there is no API method for doing this - you'd have to do it manually and understand the directory conventions).

I've adjusted my determining logic from checking schema Ids to checking template Ids as this was more straight forward and I don't think at this point in the process trying to determine schema is the right thing to do as I'm interacting with rendered content.

2 Answers 2


I've always extended the ComponentPresentationDeploy in the past. This was because I was adding to the default deployment behaviour, rather than amending it. There is some information on this in the online documentation here (login required). However, it only gives details on how to build/modify. Not why/when to do so.

Extending the ComponentPresentationDeploy class will give you access to the Component Presentation object. From this you can get the the TcmId of the Component.

I've not tested this (and some of this code may now be deprecated), but the following code may give you a start on getting the Schema Id:

protected void processComponentPresentation(ComponentPresentation cp, File cpfile) {
    TCMURI id = cp.getComponentKey().getId();
    ItemDAO dao = (ItemDAO) StorageManagerFactory.getDefaultDAO("ComponentMeta");
    ComponentMeta compMeta = (ComponentMeta) dao.findByPrimaryKey(id.getPublicationId(), id.getItemId());  //NOT TEXTED - I've always just got ItemMeta here
    Integer schemaId = compMeta.getSchemaId();

For anyone else doing this, there are also some excellent nugets in Jamie's SDL Tridion World "Deployer Extensions with Eclipse" article.

  • Thanks Jon - I had reached a similar conclusion although I'm moving more towards detecting the template ID rather than schema ID. It seems that your code is trying to get information from storage - if my extension is handling something that's not been published before would there be any meta info to actually retrieve?
    – Neil
    Apr 4, 2013 at 7:33

Try below code for component presentation (the rendered output) content (kindly pardon the JAVA syntax as I am a C# Guy):

int publicationID = componentPresentation.getComponentKey().getId().getPublicationId();
String componentID = componentPresentation.getComponentKey().getId().toString();
String templateID = componentPresentation.getTemplateKey().getId().toString();

com.tridion.dcp.ComponentPresentationFactory cpf = new 

String cp = cpf.getComponentPresentation(componentID, templateID).getContent();

cp will be your dynamic component presentation being published.

  • Thanks Pankaj. But if I'm publishing something I haven't published before would getComponentPresentation wtill work? I'd kind of assumed it was "safer" to try and use the component presentation file as part of the package.
    – Neil
    Apr 4, 2013 at 7:35
  • Of-course it would work, please note in that case you may face issues related to internal link resolving or if you want to put a check like whether the item is published or not as the publishing process runs in a transaction and by default Deployer Extension will get invoked pre-commit. However, you can configure the Deployer Extension to work in Post-Commit phase and in that case all such problems will get resolved (in the deployer config you need to give attribute like Phase="PostCommit" or something like that - please refer the documents for exact syntax) Apr 5, 2013 at 3:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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