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

Scaling Policies

This post is part of a bigger topic Autoscaling Publishers in AWS . In a previous post we talked about the Auto Scaling Groups , but we didn't go into details on the Scaling Policies. This is the purpose of this blog post. As defined earlier, the Scaling Policies define the rules according to which the group size is increased or decreased. These rules are based on instance metrics (e.g. CPU), CloudWatch custom metrics, or even CloudWatch alarms and their states and values. We defined a Scaling Policy with Steps, called 'increase_group_size', which is triggered first by the CloudWatch Alarm 'Publish_Alarm' defined earlier. Also depending on the size of the monitored CloudWatch custom metric 'Waiting for Publish', the Scaling Policy with Steps can add a difference number of instances to the group. The scaling policy sets the number of instances in group to 1 if there are between 1000 and 2000 items Waiting for Publish in the queue. It also sets the

Toolkit - Dynamic Content Queries

This post if part of a series about the  File System Toolkit  - a custom content delivery API for SDL Tridion. This post presents the Dynamic Content Query capability. The requirements for the Toolkit API are that it should be able to provide CustomMeta queries, pagination, and sorting -- all on the file system, without the use third party tools (database, search engines, indexers, etc). Therefore I had to implement a simple database engine and indexer -- which is described in more detail in post Writing My Own Database Engine . The querying logic does not make use of cache. This means the query logic is executed every time. When models are requested, the models are however retrieved using the ModelFactory and those are cached. Query Class This is the main class for dynamic content queries. It is the entry point into the execution logic of a query. The class takes as parameter a Criterion (presented below) which triggers the execution of query in all sub-criteria of a Criterio

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