4

I'm using Tridion 2013 SP1, and I'm wondering how to extend a page metadata in a deployer extension. I need to extract the existing one and add new ones.

BTW, As a best practice, Should I do it at Processor level or Module level?

Thanks in advance.

UPDATE

So far, I'm trying to do it extending PageDeploy module like this:

public class PageMedatadaAggregatorModule extends com.tridion.deployer.modules.PageDeploy {

   private static TLogger logger = TLogger.getLogger(PageMedatadaAggregatorModule.class);

   public PageMedatadaAggregatorModule(Configuration config, Processor processor)
           throws ConfigurationException {

       super(config, processor);
   }

   @Override
   public void processPage(Page page, File pageFile) throws ProcessingException {

        logger.info("processPage: <<< Starting processing Page.");

        Document pageDocument = null;

        if (pageFile.exists() {
                pageDocument = Utils.getDocument(pageFile);
        }

        if (pageDocument != null) {
            addMetadata(page, pageDocument);
        }

        logger.info("processPage: <<< Finished processing Page.");

        super.processPage(page, pageFile);
   }

    /**
     * Adds new metadata to the page.
     * 
     * @param Page
     *            Page metadata.
     * @param File
     *            Page file.
     *            
     * @exception ProcessingException.
     */
    private void addMetadata(Page page, Document pageDocument) {
        // Add metadata to the page

        // Which of the following methods should I use? Any example?

        CustomMetaData customMetaData = new CustomMetaData();
        page.setRenderAddedMetaData(renderAddedMetaData);
        page.setRawCustomMeta(rawCustomMeta);
        page.setCustomMetaData(customMetaData);
    }
}

I don't find examples nor documentation regarding the following methods, Which of the following methods should I use? Any example?

page.setRenderAddedMetaData(renderAddedMetaData);
page.setRawCustomMeta(rawCustomMeta);
page.setCustomMetaData(customMetaData);
2

My suggestion would be do to this change during publish at templating level before the package is created from publisher. Depending upon the publish target, you can take action on the page object as needed. The advantage of doing this at the templating level are a couple:

  1. You can reuse the same template if you need for any other publishing target by adding a condition for targets where you want same changes, while if you do at the deployer level you have to do it twice (assuming you don't share deployers across targets)
  2. The page is being transformed during the publishing process by the templates, so it is appropriate time to modify the object and make changes as you will like based on the requirements. It will save time for not needing to transform it again at the deployer level
  • Do you have any example where I can see how to add metadata to a Page using the template approach? – polonskyg Dec 14 '16 at 1:54
1

Since you are extending page metadata which will be stored in broker database, deployer extension is not the recommended approach.

Instead of deployer extension, use storage extension, which specifically intended for extending data. Reference for storage extension: reference

Also, refer to article to find out difference between storage extension and deployer extension.

  • 1
    It is my understanding that I cannot access Page Metadata in a Storage Extension. Can I? If so, Do you have any snippet of code on how to do it, since I moved to Deployer Extension just because of that. – polonskyg Dec 12 '16 at 20:05
  • ohh, I was not aware that it is not possible. Let me check – Hiren Kaku Dec 12 '16 at 20:17

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.