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

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

Debugging a Tridion 2011 Event System

OK, so you wrote your Tridion Event System. Now it's time to debug it. I know this is a hypothetical situtation -- your code never needs any kind of debugging ;) but indulge me... Recently, Alvin Reyes ( @nivlong ) blogged about being difficult to know how exactly to debug a Tridion Event System. More exactly, the question was " What process do I attach to for debugging even system code? ". Unfortunately, there is no simple or generic answer for it. Different events are fired by different Tridion CM modules. These modules run as different programs (or services) or run inside other programs (e.g. IIS). This means that you will need to monitor (or debug) different processes, based on which events your code handles. So the usual suspects are: dllhost.exe (or dllhost3g.exe ) - running as the MTSUser is the SDL Tridion Content Manager COM+ application and it fires events on generic TOM objects (e.g. events based on Tridion.ContentManager.Extensibility.Events.CrudEven