Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tridion 2009 SP1: Image Thumbnails - How to publish the original image as well?

I have a Dynamic Component Template which publishes XML to the Broker database which is then dynamically loaded using the Component Presentation factory.

This Xml contains URLs to Images. I need a thumbnail and a full image to be available. I have managed to use the Image Resizer TBB to produce the thumbnails however, I was hoping that this would add separate package items and binaries that could be referenced, but it seems to overwrite the full size images.

Is there a way I can get both into my Xml and the Package without writing my own custom TBB?

like image 719
Rob Stevenson-Leggett Avatar asked Nov 30 '25 09:11

Rob Stevenson-Leggett


1 Answers

Tridion Content Delivery can store multiple variants of the same Multimedia Component. Each such variant has an ID that identifies it and the variant with no ID (of in newer versions #def# as its ID) is known as the default variant.

When you reference an image from a DWT, it is automatically added as an item to package when the render engine executes your DWT. This item is then later processed by the default "Publish Binaries in Package" TBB that is part of the Default Finish Actions. The Publish Binaries in Package TBB publishes binaries by calling AddBinary on them - you can verify this by looking at the original code for most default TBBs that was published on the Tridion forum here (login required).

appliedTemplateUri = new TcmUri(item.Properties[Item.ItemPropertyTemplateUri]);
...
engine.AddBinary(itemUri, appliedTemplateUri, targetStructureGroup, 
                 data, fileName);

The AddBinary method that is called is defined in the TOM.NET CHM as:

public abstract string AddBinary(
    TcmUri componentUri,
    TcmUri templateUri,
    TcmUri targetLocation,
    byte[] data,
    string fileName
)
  • componentUri The multimedia component this item refers to
  • templateUri The template in whose context this AddBinary call is executed (used as variant id)
  • targetLocation The location to publish the binary to (if null, publish to standard path)
  • data The binary data to publish
  • fileName The filename to publish the file under

So as you can see in that last call to AddBinary, the Publish Binaries in Package TBB uses a property (look here if you've never heard of Item.Properties) to determine which variant to publish (and publishes the binary as the default variant if the property is not present).

With all this knowledge in hand, the task becomes quite simple: you have to ensure that there are two binary Items in the package for your MMC, each with a different value of the Item.ItemPropertyTemplateUri property.

The default Image Resizer TBB replaces the binary content of the Item it resizes and does not set this property. So the least code you'll have to write is either a pre-processor TBB that duplicates the item or a post-processor TBB that re-adds the item. In both cases the TBB will have to set the "magic" property too.

Useful links:

  • the original C# source code of the default template building blocks
  • a page describing Item.Properties and how to see what they do in your compound template
  • a recent post on the SDL Tridion forum about the same topic (login required)
like image 121
Frank van Puffelen Avatar answered Dec 02 '25 04:12

Frank van Puffelen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!