Skip to main content

Demystifying Tridion Code Generation

During publishing Tridion generates (or better said transforms) some code, depending on certain settings, such as:
  • Publication Target Target Language;
  • Component Template Output Format;
  • Deployer config TCDLEngine Properties;
Let's see some details about these parameters and how they work with each other.

Publication Target

The Target Language specifies the destination language that the Deployer should transform any TCDL (Tridion Content Delivery Language) code it finds in the Transport Package. You can think about this language as the 'website language' or the Tridion code that is generated by a Page Template (we will tackle the Component Template code in the next section). Common values for Target Language are:
  • ASP.NET - select this if you are publishing to a .NET website and the Deployer should transform to .NET code;
    Generated code sample:
    <tridion:ComponentPresentation runat="server" PageURI="tcm:4-5-64" ComponentURI="tcm:4-3" TemplateURI="tcm:4-7-32"/>

  • JSP - select this if you are publishing to a Java website and the Deployer should transform to Java/JSP code;
    Code sample:
    <tridion:ComponentPresentation pageURI="tcm:4-5-64" componentURI="tcm:4-3" templateURI="tcm:4-7-32"/>
  • REL - (Render Engine Language) select this if you are publishing to an OData Deployer or if you are publishing a dynamic website to the Content Delivery Database;
    Code sample:
    <tcdl:ComponentPresentation type="Dynamic" componentURI="tcm:4-3" templateURI="tcm:4-7-32" xmlns:tcdl="http://www.tridion.com/ContentDelivery/5.3/TCDL" />

  • None - TCDL is not transformed by Deployer (in fact all TCDL code is stripped out and DCPs are embedded into the Page)

Also, the Target Language is used by PageContentAssembler class, when it retrieves the content of a Page. This functionality is mainly used when serving a page through the OData service (aka Content Delivery Webservice).

Component Template

The Output Format specifies the language (or format) of a DCP. This property only makes sense for Dynamic Component Presentations.

First, this property instructs the Deployer to transform the DCP content to the specified language (or format). Common Output Format values are:
  • HTML Fragment - DCP is published with extension .txt and all TCDL code inside it (if any) is stripped out;
  • ASCX Control - DCP is published with extension .ascx and code inside it is .NET:
    <tridion:ComponentLink runat="server" PageURI="tcm:4-455-64" ComponentURI="tcm:4-393" TemplateURI="tcm:0-0-0" AddAnchor="false" LinkText="Read more" LinkAttributes="" TextOnFail="true"/>

  • JSP Scripting - DCP is published with extension .jsp and code inside it is Java/JSP:
    <tridion:ComponentLink pageURI="tcm:0-0-0" componentURI="tcm:4-393" templateURI="tcm:0-0-0" addAnchor="false" linkText="Read more" linkAttributes="" textOnFail="true"/>
  • REL - DCP is published with extension .rel (should be in fact published to CD DB) and code inside is TCDL (no transformation takes place during Deployment):
    <tcdl:Link type="Component" origin="tcm:0-0-0" destination="tcm:4-393" templateURI="tcm:0-0-0" linkAttributes="" textOnFail="true" addAnchor="false" variantId="">Read more</tcdl:Link> 

Second, the Output Format specifies how the DCP content is handled when presented on the website. The ComponentPresentationAssembler class should be used for this. Depending on the format, the content is either retrieved directly, or first executed and then result of the execution is returned.

Deployer Config

The Deployer configuratin under node Deployer/TCDLEngine/Properties influences the way the TCDL code produced by the Publisher gets transformed into the language specific code. The most commonly used are the following:

    <Property Name="tcdl.dotnet.style" Value="controls" />
    <Property Name="tcdl.jsp.style" Value="tags" />

When either of these properties is present, the code for the respective language will be generated using Tridion user controls or custom tags.

If either of the property is missing, code generation falls back on default language -- the old school inline JSP or .NET scriptlets.

Example scriptlet for JSP:

<%@ page import="com.tridion.web.jsp.JSPPage"%>
<%@ page import="com.tridion.web.jsp.ComponentPresentationAssembler"%>
<%
JSPPage waiPage = null;
ComponentPresentationAssembler cpAssembler = null;
%>
<%
waiPage = new JSPPage(pageContext, "tcm:4-455-64");
cpAssembler = new ComponentPresentationAssembler(waiPage);
%>
...
<%out.print(cpAssembler.getContent("tcm:4-395","tcm:4-423-32"));%>


Example scriptlet for .NET:

<%@ Import namespace="Tridion.ContentDelivery.WAI"%>
<%
ComponentPresentationAssembler componentPresentationAssembler = null;
%>
<%
componentPresentationAssembler = new ComponentPresentationAssembler("tcm:4-455-64",Page);
%>
...
<%Response.Write(componentPresentationAssembler.GetContent("tcm:4-395","tcm:4-423-32"));%>


So to conclude, there are several settings that allow flexible configuration of code generation (and I haven't event talked about Page and DCP TCDL Transformers). These settings offer great power of configuring how code is handled by Tridion API, but at the same time it also gives room for error. Some of the common mistakes are the following (make sure you avoid them):

  • language mismatch between Target Language and Output Format (e.g. one set to None, the other to   JSP);
  • location misconfiguration: e.g. REL DCP published to the file system, or JSP DCP published to CD DB;

Comments

Nivlong said…
If publishing to the file system I know we lose REL. Can we still get component links and/or component presentations without a storage (broker) database?
Mihai Cădariu said…
That is definitely still possible. Things you lose without a CD DB are taxonomies, custom meta and the dynamic content query functionality.

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...