Skip to main content

RenderedItem Metadata and Instruction

Ever wondered what the methods AddMetadata and AddInstruction do in the RenderedItem class? Did you ever noticed they were there? I’m talking about Tridion.ContentManager.Publishing.Rendering.RenderedItem and the methods:

  • public void AddMetadata(XmlElement metadata)
  • public void AddInstruction(InstructionScope scope, XmlElement instruction)

They were introduced a while back (IIRC, R5.2) and they are responsible with sending metadata from the Content Manager to the Content Delivery, or more exactly to the Deployer. This is a great idea and it’s unfortunate very few of us know about them. What’s even more unfortunate is that this is your typical Tridion half-implementation. Namely, while there is this nice API to send metadata to the Deployer, there is no API whatsoever to read it once it reaches the Deployer. You are on your own. But, let’s see what they do.

AddMetadata(XmlElement metadata)

Documentation states: "The metadata parameter can contain any valid XML structure which can be processed at the Content Delivery side. [...] When a Page with a PageTemplate is rendered this added metadata is available on the Page at the Content Delivery side. When a Component with a ComponentTemplate is rendered this added metadata is available on the Page when the ComponentPresentation is embedded, in case of a Dynamic ComponentPresenation the added metadata is available on the ComponentPresentation at the Content Delivery Side."

What is unclear is the "can be processed at the Content Delivery side". This should read, "can be processed during Deployment, in either a Deployer processor/module or in a Storage extension". This metadata is available as XML inside certain files (we'll see exactly in which ones) in the transport package and cannot be accessed after the Deployment/Publishing finishes. This metadata does not end up in any Content Delivery database tables or file system. Also, this information is only available while publishing and not for unpublish.

In the example below, I'm setting the Metadata XML node of a Folder as RenderedItem metadata. Of course, any XMLElement would do, I am simply using an easy way to get some meaningful metadata and attach it. The Folder metadata contains an Embedded Schema field "CDNSettings" that has two sub-fields: "CDN" and "UrlBasePath". The TOM.NET code looks like this:

Folder folder = engine.GetObject("tcm:14-6-2") as Folder;
engine.PublishingContext.RenderedItem.AddMetadata(folder.Metadata);

I placed the code above in a C# Fragment TBB that I added to a Dynamic Component Template.

When publishing a Page that contains a CP with that Dynamic CT, the following metadata is generated (as XML node) and it is available in the transport package in the component_presentations.xml file:

<ComponentPresentations>
...
    <RenderingMetadata>
      <Metadata xmlns="uuid:5bd95ff5-a509-4490-b37d-211ac5907c53">
      <CDNSettings>
        <CDN>Akamai</CDN>
        <UrlBasePath>http://cdn.akamai.com</UrlBasePath>
      </CDNSettings>
    </RenderingMetadata>
...

Placing the C# TBB on the Page Template will have as effect the generation of RenderingMetadata node in the transport package inside file pages.xml:

<Pages>
...
    <RenderingMetadata>
      <Metadata xmlns="uuid:5bd95ff5-a509-4490-b37d-211ac5907c53">
      <CDNSettings>
        <CDN>Akamai</CDN>
        <UrlBasePath>http://cdn.akamai.com</UrlBasePath>
      </CDNSettings>
    </RenderingMetadata>
...

AddInstruction(InstructionScope scope, XmlElement instruction)

Documentation states: "The instruction parameter can contain any valid XML structure which can be processed at the Content Delivery side. [..] Adding the instruction with a global scope is available at instruction level at the Content Delivery side. When a Page with a PageTemplate is rendered with adding a local instruction this instruction is available on the Page module at the Content Delivery side. When a Component with a ComponentTemplate is rendered with adding a local instruction this instruction available on the Page module when the ComponentPresentation is embedded, in case of a Dynamic ComponentPresenation the added local instruction is available on the ComponentPresentation module at the Content Delivery Side."

Again, the documentation is unclear regarding the "can be processed at the Content Delivery side". Same as with AddMetadata, the instruction XmlElement can be processed during deployment in either the Deployer or a Storage Extension. This information is not stored anywhere after deployment (not in file system or database based Brokers).

The InstructionScope determines where the instruction XML is available in the transport package:

  • InstructionScope.Local

Publishing using the code below will result in the RenderingInstructions node being populated with the folder metadata XML into either the component_presentations.xml or pages.xml in the transport package.

Folder folder = engine.GetObject("tcm:14-6-2") as Folder;
engine.PublishingContext.RenderedItem.AddInstruction(InstructionScope.Local, folder.Metadata);

Adding instruction in a Component Template, will create the following structure in the component_presentations.xml:

<ComponentPresentations>
...
  <ComponentPresentation IsRendered="true">
    <RenderingInstructions>
      <Metadata xmlns="uuid:5bd95ff5-a509-4490-b37d-211ac5907c53">
        <CDNSettings>
          <CDN>Akamai</CDN>
          <UrlBasePath>http://node.akamai.com</UrlBasePath>
        </CDNSettings>
      </Metadata>
    </RenderingInstructions>
...

Adding instruction in a Page Template, will create the following structure in the pages.xml:

<Pages>
...
    <RenderingInstructions>
      <Metadata xmlns="uuid:5bd95ff5-a509-4490-b37d-211ac5907c53">
        <CDNSettings>
          <CDN>Akamai</CDN>
          <UrlBasePath>http://node.akamai.com</UrlBasePath>
        </CDNSettings>
      </Metadata>
    </RenderingInstructions>
...

  • InstructionScope.Global

Using InstructionScope.Global, will generate the following XML structure in the instructions.xml file in the transport package:

<ProcessorInstructions version="6.1.0.996">
...
  <RenderingGlobalInstructions>
    <Metadata xmlns="uuid:5bd95ff5-a509-4490-b37d-211ac5907c53">
      <CDNSettings>
        <CDN>Akamai</CDN>
        <UrlBasePath>http://node.akamai.com</UrlBasePath>
      </CDNSettings>
    </Metadata>
  </RenderingGlobalInstructions>
...

Usage

On its own, this mechanism is really just a half-implementation. It is up to the implementer to read this XML on the Content Delivery side (read Deployer or Storage extension) during publishing. Remember, this won't work during unpublish, as no templates are executed (rendered) during unpublishing. What's really annoying is that the implementer is resposible with writing the code to extract the XmlElement metadata or instruction from their respective files in the transport package!

I would use this mechanism to set, via templating, information that I want to have available during deployment, knowing that this information is not going to be stored on the Content Delivery side.

Most likely I would implement a POJO or in fact a JavaBean and use JAXB to unmarshal the XML into a JavaBean. An alternative is to build an XML DOM and query it with XPath selectors.

Comments

Popular posts from this blog

Running sp_updatestats on AWS RDS database

Part of the maintenance tasks that I perform on a MSSQL Content Manager database is to run stored procedure sp_updatestats . exec sp_updatestats However, that is not supported on an AWS RDS instance. The error message below indicates that only the sa  account can perform this: Msg 15247 , Level 16 , State 1 , Procedure sp_updatestats, Line 15 [Batch Start Line 0 ] User does not have permission to perform this action. Instead there are several posts that suggest using UPDATE STATISTICS instead: https://dba.stackexchange.com/questions/145982/sp-updatestats-vs-update-statistics I stumbled upon the following post from 2008 (!!!), https://social.msdn.microsoft.com/Forums/sqlserver/en-US/186e3db0-fe37-4c31-b017-8e7c24d19697/spupdatestats-fails-to-run-with-permission-error-under-dbopriveleged-user , which describes a way to wrap the call to sp_updatestats and execute it under a different user: create procedure dbo.sp_updstats with execute as 'dbo' as

I Have Gone Dark

Maybe it's the Holidays, but my mood has gone pretty dark. That is, regarding the look and feel of my computer and Tridion CME, of course. What I did was to dim the lights on the operating system, so I installed Placebo themes for Windows 7 . I went for the Ashtray look -- great name :) My VM looks now like this: But, once you change the theme on Windows, you should 'match' the theme of your applications. Some skin easily, some not. The Office suite has an in-built scheme, which can be set to Black , but it doesn't actually dim the ribbon tool bars -- it looks quite weird. Yahoo Messenger is skinnable, but you can't change the big white panels where you actually 'chat'. Skype is not skinnable at all. For Chrome, there are plenty of grey themes. Now i'm using Pro Grey . But then I got into changing the theme of websites. While very few offer skinnable interfaces (as GMail does), I had to find a way to darken the websites... Enter Stylish -- a pl

REL Standard Tag Library

The RSTL is a library of REL tags providing standard functionality such as iterating collections, conditionals, imports, assignments, XML XSLT transformations, formatting dates, etc. RSTL distributable is available on my Google Code page under  REL Standard Tag Library . Always use the latest JAR . This post describes each RSTL tag in the library explaining its functionality, attributes and providing examples. For understanding the way expressions are evaluated, please read my post about the  Expression Language used by REL Standard Tag Library . <c:choose> / <c:when> / <c:otherwise> Syntax:     <c:choose>         <c:when test="expr1">             Do something         </c:when>         <c:when test="expr2">             Do something else         </c:when>         <c:otherwise>             Do something otherwise         </c:otherwise>     </c:choose> Att