4

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

4

1 回答 1

4

AddBinary() 是首选方法。我相信它是在 R5.3 中引入的。它让我们可以选择制作多个版本(变体)的二进制文件,并将它们放在特定的 SG 中。您在文件名中看不到变体 ID 的原因是它在 Broker 中用作元数据来检索(或链接到)多媒体组件的特定变体。如果您查看 TOM.NET API,您将看到诸如变体前缀(将成为文件名的一部分)之类的附加参数。

如果您在代码中同时使用这两种技术,您实际上可能会遇到问题。我强烈建议您将 PublishBinary() 视为“仅用于向后兼容”,并使用较新的方法。

快乐编码

克里斯

于 2012-02-20T22:15:13.870 回答