razortridionrazor-mediator

Publishing PDFs when using Tridion Razor templates


I am having a problem publishing binaries (PDF files) from Tridion using Razor Templating.

I have a Component Template that is set to 'Published as a Dynamic Component' with a single linked Multimedia Schema.

I am using the Razor Mediator eXtension and the Component Template contains two Template Building Blocks:

  1. A Razor Template that output some HTML and the link to the binary in the Multimedia Component.
  2. The Default Finish Actions TBB containing the following:
    • Publish Binaries in Package
    • Link Resolver
    • Target Group Personalization
    • Cleanup Template
    • Convert Xml to Html

The Razor Template contains the following code (I have simplified this slightly): enter image description here

This appears to be resolving the binary link correctly and produces the following Dynamic Component Presentation: enter image description here

The problem that I am having is that the binary itself is never added to the package and so does not get published.

As the Razor Mediator has an 'extractBinaries' setting in the Tridion.ContentManager.config file then I suspect that the binaries should be added on to the package by the mediator. I have made sure that the extractBinaries setting is set to 'true', however the binary is not being added to the package (although the Multimedia Component being processed is on the package as a tridion/component item).

Does anyone know if this functionality is available and working in the Razor Mediator please? I suspect that Razor Mediator is expecting the link code to be in a specific format, but I cannot find anything on this in the documentation.

I have also tried adding the 'Extract Binaries from Html' TBB to the Component Template (following the Razor Template) but I get the following error: "The item Output must have property TCMURI specified". I suspect that this is due to the way that the Razor Mediator is adding the 'Output' item to the package.

I could write a new TBB to make sure that the binary is added to the package, but I would prefer to avoid doing this if the functionality is already available with the Razor Mediator.

Thanks in advance.

P.S. Apologies for the images. Stackoverflow didn't want to format the code correctly.


Solution

  • Unfortunately the Razor Mediator currently doesn't add the PDF binary to the package when in an tag (thus not getting picked up by the Publish Binaries TBB), though I have a pretty good feeling that version 1.3 will be taking care of this ;).

    In the meantime, you can use a "Add Unresolved Binary Dependencies" type of TBB. I don't have it on hand at the moment, but let me know if you need it and I'll post the code for you later tonight.

    EDIT Cancel my statement about it not getting added to package, I was thinking of a different scenario.

    Try the following instead:

    <a href="@Component.ID">@Component.Metadata.title</a>