Skip to main content

Posts

Showing posts from March, 2012

Publishing Images as Variants

For several versions ( was it 5.3? ) it is possible to publish Multimedia Components as variants. It means that in template code, we can choose to publish a representation of the MMComponent instead of the original. When unpublishing a MMComponent, all its variants are unpublished as well. A big use case of variants is publishing images with different resolutions. In Tridion, we keep only one version of the MMComponent (i.e. the one with highest resolution), and during publishing we can produce as many variants as we need via templating. This post details this use case. I wrote a TBB that performs the resize. The TBB takes 4 parameters: Width - the new width (in pixels) of the image (optional); Height - the new height (in pixels) of the image (optional); Aspect Ratio - Yes/No whether to keep the original's aspect ratio (boolean, optional); ImageTcmUri - the TcmUri of the image (mandatory); When Aspect Ratio = Yes , either Width or Height need be specified. Otherw

Which AddBinary (not) To Use?

If you look at the CHM documentation for TOM.NET, you will see a plethora of AddBinary methods and their  overloads. Why so many? I don't know, maybe for flexibility... While some of them are clearly marked as 'internal', some are deprecated and the rest are just out there. So which ones to use? Well, the story is a bit longer here. Clearly, don't use those marked as 'internal'. However, the deprecated (or actually Obsolete) methods are the tricky ones. It seems they are only deprecated since Tridion 2011SP1, while in fact they are buggy. Different behaviors have been reported on them -- binaries becoming un-managed once published. This means, a Unpublish action would leave that binary behind on the Content Delivery side. So which are the safe to use AddBinary methods? In Tridion.ContentManager.Publishing.Rendering. RenderedItem : AddBinary(Component); AddBinary(Component, String); AddBinary(Component, StructureGroup); AddBinary(Component, StructureGr

CWA Navigation Custom Tag

Normally with Tridion, we do navigation as a transformation between a navigation XML with an XSLT stylesheet. We plug some parameters into this transformation in order to highlight the current context. In CWA (Content Web Application) terms, this approach still applies only with some modification. Namely, the XML and XSLT are usually both published to the CD (Content Delivery) database. This setup implies that we need a special way or reading the XML/XSLT, prior to performing the actual transformation. To this respect, I created a custom Java tag CwaTransformXml that first ensures the XML and XSLT files are extracted from the CD DB and serialized as files on the file system, then second, it performs the XSLT transformation. CwaTransformXml has the following attributes: xml - the XML file path; xslt - the XSLT file path; paramName - the name of the parameter to pass into the transformation; paramValue - the value of the parameter; out - the variable name to set in PageContex

Strange Compilation Error about Missing Assembly Reference

I was coding some Tridion TOM.NET stuff recently, when I got the by now infamous error " The type or namespace name XXX does not exist in the namespace YYY... are you missing an assembly reference? ". Obviously, I had the ' using ' statement in place and also the correct reference to the assembly. So what could cause the compilation error? It turned out the culprit was the .NET framework I was using: .NET Framework 4 Client Profile . Changing it to .NET Framework 4 solved it! So go to your project's properties, tab Application, drop-down Target Framework and do the right thing ;)

Get All ApplicationData with Given ID

Did you know that in Tridion 2011SP1 it is now possible to retrieve all items that have a particular Application Data ID associated? This method basically allows you to search for a given Application Data ID and it returns the TCMURIs of all items that have that AppData ID associated. This topic would have been very useful when I developed the AppDataInspector Powertool . At that time, in Tridion 2011GA, this functionality was not available. I would have liked to be able to search for a given Application Data ID. Instead, the tool only reads AppData on the ' current ' item. [ Note to self : add "search by id" functionality to AppDataInspector] Core Service You can use Core Service method:  ICoreService2011 . GetSubjectIdsWithApplicationData Gets a list of TcmUri of subjects which have application data of the specified applicationId associated. Namespace:  Tridion.ContentManager.CoreService The sample below is taken from my Core Service Client blog post:

Get Current Publish Transaction

I was struggling a while back to retrieve the current Publish Transaction from template code. This is the Publish Transaction that is currently being executed in the Publisher. I needed it to identify who sent the current item to publish and with which priority. I found out it wasn't easy to retrieve the current Publish Transaction. In fact, it was impossible to identify it with absolute certainty. I tried looking at the Publishing Queue and pick the transaction ' In Progress ' or with status Rendering . However, this doesn't work reliably due to possible concurrent rendering threads or even multiple Publishers, so it is impossible to know for sure which exactly is the current Publish Transaction. Then the following hack came to light thanks to a post by Chris Summers . And what a hack it is indeed: take the Binary storage path of the RenderInstruction and extract the  Publish Transaction  TCMURI from it . The Binary storage path looks something like  C:\Temp\t

Query for Component Presentations

Use LimitFilter, SortParameter, CPAssembler, CPFactory The following sample queries the Content Delivery database for Components in a given Publication by using the PublicationCriteria and ItemTypeCriteria . It also uses a ResultFilter in the form of a LimitFilter and a SortParameter to only retrieve a maximum set of Components in the given sort order (descending according to their last-publish-date). For each of the identified Components (if any), we retrieve the Dynamic Component Presentation using the CT with the highest priority. Finally, we feed these DCPs into the ComponentPresentationAssembler in order to retrieve their actual content. <%     JSPPage jspPage = new JSPPage(pageContext, "tcm:83-3246-64" );     cpAssembler = new ComponentPresentationAssembler(jspPage);     Query query = new Query();     PublicationCriteria publicationCriteria = new PublicationCriteria( 83);     ItemTypeCriteria itemTypeCriteria = new ItemTypeCriteria( ItemTyp

Query for Components

Using Criteria In this sample we are searching for Components in a given Publication. Therefore we define two search criteria: PublicationCriteria - to limit result to the given Publication ID; ItemTypeCriteria - to limit results to only type Component; We then perform a logical AND between these criteria and feed that into the Query. <%     Query query = new Query();     String items[] = query.executeQuery();     out.println( "<p><b>Simple Query: </b>" + list(items) + "</p>" );     PublicationCriteria publicationCriteria = new PublicationCriteria(83);     query.setCriteria(publicationCriteria);     items = query.executeQuery();     out.println( "<p><b>Publication=83 Query: </b>" + list(items) + "</p>" );     ItemTypeCriteria itemTypeCriteria = new ItemTypeCriteria(ItemTypes.COMPONENT);     AndCriteria andCriteria = new AndCriteria(publicationCriteria, ite

Display Dynamic Component Presentation Samples

Approach using Tridion custom tags                            i.       Use Dynamic Component Template                         ii.       Generated code: < tridion:ComponentPresentation pageURI = "tcm:83-3246-64" componentURI = "tcm:83-3235" templateURI = "tcm:83-3245-32" />                       iii.       Change Output Format to JSP Scripting                       iv.       Change cd_storage_conf.xml to publish under Tomcat temporary webroot                         v.       Add JSP directives to Dynamic CT <%@ page contentType = "text/html; charset=UTF8" %> <%@ taglib uri = "cd_tags" prefix = "tridion" %> Approach using Java API                            i.       Use the ComponentPresentationAssembler             JSPPage jspPage = new JSPPage(pageContext, "tcm:83-3246-64" );             ComponentPresentationAssembler cpAssembler = new ComponentPresentatio