Reputation: 2887
I've been able to publish binaries in an XSLT component template (CT) by referencing the TcmScriptAssistant namespace (xmlns:tcmse="http://www.tridion.com/ContentManager/5.1/TcmScriptAssistant") and using the following:
<h2>PublishBinary()</h2>
<xsl:element name="a">
<xsl:attribute name="href">
<xsl:value-of select="tcmse:PublishBinary(string(./@xlink:href))" />
</xsl:attribute>
<xsl:value-of select="./@xlink:title" />
</xsl:element>
I recently tried AddBinary:
<h2>AddBinary() with webdav</h2>
<xsl:element name="a">
<xsl:attribute name="href">
<xsl:value-of select="tcmse:AddBinary(string(./@xlink:href), '/webdav/040 CreateandBreak/Root/Media/Image', 'some_variant')" />
</xsl:attribute>
<xsl:value-of select="./@xlink:title" />
</xsl:element>
The resulting markup for both:
<h2>PublishBinary()</h2>
<a href="/Media/buddy_tcm7-274.jpg">buddy</a>
<h2>AddBinary() with webdav</h2>
<a href="/Media/Image/buddy.jpg">buddy</a>
I can see addBinary used a different folder (structure group) as provided in the second parameter.
Did I enter the third parameter for String variantID wrong? I'm not sure if I should see its text in the .jpg name.
Any other difference between PublishBinary and AddBinary, especially when using XSLT CTs?
I'm trying to understand if one should be used over the other.
For clarification, I believe this is the Tridion Object Model AddBinary under the TCMScriptAssistant class (not TOM.NET). I'm sure XSLT CTs will remain supported, but I'll follow up with a different question on better ways to handle binaries, possibly in modular templates.
Other info: - Tridion 2011 SP1 Schema has links to multimedia Component embedded on page with XSLT CT to make "static" component presentations
Upvotes: 4
Views: 507
Reputation: 10163
AddBinary() is the preferred method. It was introduced with R5.3 I believe. It gave us the option to make multiple versions (variants) of binaries, and place them in specific SGs. The reason you don't see the variant ID in the file name is that it is used as metadata in the Broker to retrieve (or link to) specific variations of a multimedia components. If you look at the TOM.NET API you will see additional parameters for things like variant prefix (which will become part of the file name).
You can actually run into problems if you use both techniques in your code. I strongly suggest you think of PublishBinary() as a "for backward compatibility only", and use the newer method.
Happy coding
Chris
Upvotes: 4