Publish PDF files using Tridion Razor templates

I am having trouble publishing binary files (PDF files) from Tridion using Razor Templating.

I have a component template that is configured to "Published as a dynamic component" with a single, connected multimedia scheme.

I am using Razor Mediator eXtension , and the component template contains two templates:

  • A Razor template that outputs some HTML and a link to a binary file in a multimedia component.
  • Default TBB completion steps that include the following:
    • Publishing binary files in a package
    • Link resolver
    • Target group personalization
    • Cleaning pattern
    • Convert Xml to HTML

The Razor template contains the following code (I simplified this a bit): enter image description here

This apparently resolves the binary link correctly and creates the following dynamic representation of the components: enter image description here

The problem that I encountered is that the binarium itself is never added to the package and therefore is not published.

Since the Razor broker has an extractBinaries parameter in the Tridion.ContentManager.config file, I suspect that the binaries should be added to the package by the broker. I made sure that the extractBinaries parameter is set to true, but the binary is not added to the package (although the processed media component is in the package as a tridion / component element).

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

I also tried adding the "Extract binary from Html" TBB to the component template (after the Razor template), but I get the following error: "The Output element must have the TCMURI property specified." I suspect this is because the Razor Mediator reseller adds an Exit item to the package.

I could write a new TBB to make sure the binary was added to the package, but I would prefer not to do this if the functionality is already available through the Razor broker.

Thanks in advance.

PS Apologies for the images. Stackoverflow did not want to format the code correctly.

+6
source share
3 answers

Unfortunately, Razor Mediator does not currently add the binary PDF file to the package when in the tag (thus, it is not possible to get the Binaries TBB publication), although I have a pretty good feeling that version 1.3 will take care of this;).

At the same time, you can use the TBB type with the addition of unresolved binary dependencies. I don’t have it at the moment, but let me know if you need it, and I will send the code to you later tonight.

EDIT Cancel my expression that it is not added to the package, I was thinking of a different scenario.

Try instead:

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

This worked for me:

 @{ var item = TridionHelper.Package.CreateMultimediaItem(Component.ID); TridionHelper.Package.PushItem("CurrentMultimedia", item); } 

Of course, PublishBinariesInPackage followed, although since you can also achieve Engine in a similar way, Direct AddBinary might work.

+2
source

I did not use the Razor broker, but did you try adding TBD Default Finish Actions or Publish Binaries in Package to your template?

0
source

Source: https://habr.com/ru/post/913532/


All Articles