Documentation Center

Creating custom TCDL tags

In addition to the built-in TCDL tags used to implement standard Content Delivery functionality, you can create your own custom TCDL tags to perform custom functionality. Implement the business logic of these custom tags in Java. Your implementation is different depending on when you want to transform this tag.

Procedure

  1. Create a Java class that implements the business logic of this tag by doing one of the following:
    • If you want to transform this tag during publishing (for use by website visitors), create a class that implements the interface com.tridion.tcdl.TagHandler.
    • If you want to transform this tag at request time (for use by the web service), create a class that implements the interface com.tridion.tcdl.TagRenderer.
  2. In your Java class, implement the interface com.tridion.tcdl.TagHandlerBase by implementing the following methods:
    MethodDescription
    doStartTagShould contain code that should be executed when the start tag is encountered.
    doEndTagShould contain code that should be executed when the end tag is encountered (which would include returning the output of the application).
    requiresCodeBlockAlways set this to false.
  3. If your custom tag has attributes or subelements, implement the validation and parsing of these attributes and subelements in Java.
  4. Place your custom tag(s) in a new or existing tag bundle, an XML file that specifies all of your custom tags. A tag bundle XML file has the following format:
    <?xml version="1.0" encoding="UTF-8"?>
    <TCDLEngine>
     	<Properties>
    	  	<Property Name="myEngineProperty" Value="myEngineValue" />
    	 </Properties>
    	 <Tags>
    		  <Tag Namespace="tcdl" Name="FooApp">
    			   <Handler Class="com.mycompany.FooAppTagHandler" />
    		  </Tag>
    	 </Tags>
    </TCDLEngine>

    Create or open your custom tag bundle XML file in a plain-text or XML editor and within the element called <TCDLEngine>, do the following:

    • In the <Tags> element, add a Tag element with two attributes: Namespace, set to the value tcdl, and Name, set to the name you want to give to your tag (must be unique).
    • Inside this new Tag element, add a Handler element with two attributes: Class, set to the fully qualified name of the Java class that implements the business logic of this tag (either an implementation of TagHandler or of TagRenderer).

    Save your tag bundle XML file. If you have just created the file, give it a meaningful name, for example, MyCustomAppTagBundle.xml.

  5. Do one of the following:
    • If you want to transform this tag during publishing (for use by website visitors), open the TCDL configuration file tcdl-conf.xml.
    • If you want to transform this tag at request time (for use by the web service), open the Dynamic Content Delivery configuration file cd_dynamic_conf.xml.
  6. In either file, find the <TCDLEngine> section and just before the closing tag </TCDLEngine>, add the following:
    <TagBundle Resource="Customizations/MyCustomAppTagBundle.xml"/>

    where Customizations/MyCustomAppTagBundle.xml is the path to and name of your tag bundle file.