Reading a very good post about Custom Renderers written by Jaime Santos, I thought of sharing with you a document I wrote at the beginning of the year about the same topic.
In case you need some background information about what a Custom Renderer is, I strongly recommend you reading Jaime's post where he explains this very clearly.
The prerequsites to follow this post are as follows:
- SDL Tridion 2011 installed, with Content Manager and Content Delivery working
- Tomcat and Java installed on your development environment
- OData working
Below I provide a detailed explanation on how to create your first Custom Renderer.
1. Work on a publication
in which REL is configured as the target language in the publication target. REL needs to be the target language for a
custom renderer to work.
2. Chose a candidate Component Presentation (Component + Component Template) to which you want to add a custom renderer. During this example I will be working with a Sandwich Component Presentation.
2. Chose a candidate Component Presentation (Component + Component Template) to which you want to add a custom renderer. During this example I will be working with a Sandwich Component Presentation.
3. Set the Output Form in the Component Template to REL, this is for the custom renderer to work.
4. To render the new tcdl tag that we’ll
be creating add the following line in the Component Template's source tab: “Price: <tcdl:Price product="[%=
Component.MetadataFields("erpId").Value(1) %]"/>”
5. Publish the Component Template which
will also publish all the components using this CT.
6. Create a new standard java project.
7. Create a Web Server Client inside
the new project using the wsdl below, this will create a set of classes that
we’ll be using in the next step. http://applications/globaldeli.com/ERP/Catalog.svc?wsdl
8. Create a new java class implementing
the TagRenderer
Interface. Just two
methods need to be modified doEndTag and doStartTag.
In this image all the needed code is shown, note that package name and
class name will be used to register the tag in step 10.
9. Export the project above as a jar file to
C:\Tomcat 6.0\webapps\cd_webservice\WEB-INF\lib
10. Now the new tag needs to be registered, in order to do so edit the file C:\Tomcat 6.0\webapps\cd_webservice\WEB-INF\classes\cd_dynamic_conf.xml. Add the following tags inside the TCDLEngine section. “tcdl” and “Price” are added in the CT in step 5, update as required. Class is set to the fully qualified name of class created in step 9. Note that any change in the config file will need a Tomcat restart to be applied.
11. While trying to render the new tag there was an error because of a missing library which is commons-discovery.jar, to
solve this problem just copy this library to C:\Tomcat
6.0\webapps\cd_webservice\WEB-INF\lib
12. You can now use the OData Web Service to check if the new tag renders the value correctly, to do so you can use the URL below, note that it is accessing just one component. Replace the IDs of publication, component and component template.
You
should see something that looks like this:
It feels like there's some lack of conceptual info on TCDL both in the blogosphere and official docs: What they're good for, i.e.: what business problem do they solve?
ReplyDeleteI have a problem at hand: need to make CM-side templates technology-invariant by using certain set of TCDL tags -AND- transform them into appropriate (Java -OR- ASP.Net) *server* markup on CD-side, depending on publishing target.
According to Jaime (the Universally Accepted Authority on the subject), the above is not possible because TCDL tranformation is only intended to produce plain HTML, that is: it must contain all the business logic *itself*.
OTOH, digging through [disassembled] sources of cd_tcdl, ugc, webforms it looks like there're at least TWO types of TCDL tranformations:
1. Renderers (is what you're talking about above)
2. Handlers
These latter are of special interest for me now: they seem capable to produce a *server* markup (JSP/aspx). But it's not clear now how to trigger this TCDLMode.TRANSFORMATION path.