Skip to main content

Writing My Own Custom REL Tag

This walkthrough describes an implementation of an SDL Tridion custom REL tag. The tag has been written in SDLTridion 2013, but it is also applicable to Tridion 2011.

Tridion comes with a number of default REL tags, but you can also add your own custom tags. A REL tag can appear inside a Page or Component Presentation content, and it has to be published to the Content Delivery Database. These tags are executed on the Content Delivery side (presentation server) in one of the following situations:
  • using the ComponentPresentationAssembler: when retrieving the content of a DCP;
  • using the PageContentAssembler: when retrieving the content of a Page;
  • using Content Delivery Web Service (OData), when retrieving either a Page or a DCP;


In my approach, I chose to use the Content Delivery Web Service (OData) approach. This means I had to install and configure an OData service. You can do so by following the installation guide from SDL Live Content.

I also needed a Deployer that publishes everything to the CD DB. I went on and installed and configured one. For details about Deployer installations, you could consult the online documentation portal as well.

Good Part First -- The Code

A custom REL tag has to implement interface com.tridion.tcdl.TagRenderer. The example tag I implement is located in package com.tridion.extensions.customrenderer, and it only outputs the string "Hello, world!". The code below shows just that. Yes, it is Java!

public class HelloWorld implements TagRenderer {

    public String doEndTag(Tag tag, StringBuffer content, TransformContext transformContext,
            OutputDocument document) throws TCDLTransformerException {
        content.append("Hello, world!");
        return content.toString();

    public int doStartTag(Tag tag, StringBuffer content, TransformContext transformContext,
            OutputDocument document) throws TCDLTransformerException {

    public boolean requiresCodeBlock(TransformContext transformContext,
            OutputDocument document, Tag tag) {
        return false;

Next, compile this class into a JAR and place it in the /lib folder among your other JARs part of your Content Delivery stack. In my case, as I'm running an OData service as a Java web application, I copied it to the [ODataWebRoot]/WEB-INF/lib folder.

The Configuration

First we need to define a mapping between a certain namespace, a tag name and its implementing class. This is used by the TCDL rendering mechanism to know that whenever it encounters that namespace and tag name, it should execute the mapped implementation class.

Create an XML file, name it my-custom-tag-bundle.xml and copy the following XML snippet in it:

        <Tag Namespace="rel" Name="HelloWorld">
            <Handler Class="com.tridion.extensions.customrenderer.HelloWorld"
                AllowCodeBlock="false" />

Place this file among the other Tridion CD configuration files in your web application. In my case, I copied it to [ODataWebRoot]/WEB-INF/classes.

Next, we need to reference the XML above in the configuration file cd_dynamic_conf.xml. Edit this file in your web application, and add the highlighted line directly inside the existing TCDLEngine node.

NOTE: There is a bug in cd_dynamic_conf.xsd, which omits to specify TagBundle as a valid child element of TCDLEngine. The example below works, though. Use it!

    <TagBundle Resource="my-custom-tag-bundle.xml" />

    <Renderer Class="com.tridion.tcdl.TCDLRenderer">
            <Property Name="prop1" Value="value1" />
            <Property Name="prop2" Value="value2" />

The CM Part

Create a Dreamweaver TBB that outputs the custom REL tag. You can choose an arbitrary name and namespace. I chose name HelloWorld and namespace rel.
Snapshot of a custom REL tag in a Dreamweaver TBB

Place the Dreamweaver TBB on a compound Page Template called REL PT.

I needed a simple Page that would output my custom REL tag. Create a simple Page, with no Component Presentations on it. Make use of the REL PT.
Snapshot of an SDL Tridion Page using the REL Page Template

Next I needed to publish the Page, so I needed a Publication Target for that. This target would have to be configured to use REL language.
Snapshot of an SDLTridion Publication Target with Target Language REL

At this stage, we can publish the Page and it would end up in the Content Delivery DB. There will be a record basically containing the page content in a CLOB column:

My custom REL tag: <rel:HelloWorld />

Testing it All...

In a browser, fire a request to the CD Web Service, requesting the Page Content for the Page you just published. My URL looks something like this:


The response is following:
Snapshot of CD Web Service response with executed custom REL tag

Notice the text inside the d:Content element: "My custom REL tag: Hello, world!". It shows how the call to the custom REL tag has been replaced by the value we output from the tag code.


Popular posts from this blog

Content Delivery Monitoring in AWS with CloudWatch

This post describes a way of monitoring a Tridion 9 combined Deployer by sending the health checks into a custom metric in CloudWatch in AWS. The same approach can also be used for other Content Delivery services. Once the metric is available in CloudWatch, we can create alarms in case the service errors out or becomes unresponsive. The overall architecture is as follows: Content Delivery service sends heartbeat (or exposes HTTP endpoint) for monitoring Monitoring Agent checks heartbeat (or HTTP health check) regularly and stores health state AWS lambda function: runs regularly reads the health state from Monitoring Agent pushes custom metrics into CloudWatch I am running the Deployer ( installation docs ) and Monitoring Agent ( installation docs ) on a t2.medium EC2 instance running CentOS on which I also installed the Systems Manager Agent (SSM Agent) ( installation docs ). In my case I have a combined Deployer that I want to monitor. This consists of an Endpoint and a

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: I stumbled upon the following post from 2008 (!!!), , 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

Event System to Create Mapped Structure Groups for Binary Publish

As a continuation of last week's Publish Binaries to Mapped Structure Group , this week's TBB is in fact the Event System part of that solution. Make sure you do check out the previous post first, which explains why and what this Event System does. To reiterate, the Event System intercepts a Multimedia Component save, take its Folder path and create a 1-to-1 mapping of Structure Groups. The original code was written, again, by my colleague Eric Huiza : [ TcmExtension ( "MyEvents" )] public class EventsManager  : TcmExtension {     private Configuration configuration;     private readonly Regex SAFE_DIRNAME_REGEX = new Regex ( @"[\W_]+" );     public EventsManager() {         ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap ();         fileMap.ExeConfigFilename = Path .GetDirectoryName( Assembly .GetExecutingAssembly().Location) + "\\EventSystem.config" ;         configuration = ConfigurationManager