1

There is a scenario to fetch an excel file which has been inserted on a multimedia component using Tridion razor mediator.

Note: I have tried to get the excel file but I am getting the TCM Id of the component with the help of a template. But I need the excel file.

1 Answer 1

1

To create and use Custom Dreamweaver Functions from a Razor Mediator.

Refer to this below example, you can create one specific to your case.

  1. Create a custom class in C# using the TOM.NET API based on ITemplate and IFunctionSource
[TemplateCallable]
public String PublishBinary(String compURI)
{
    Component comp = mEngine.GetObject(compURI) as Component;

    String publishPath = String.Empty;

    if (comp != null && comp.BinaryContent != null)
    {
        Binary pubBinary = mEngine.PublishingContext.RenderedItem.AddBinary(comp);

        publishPath = pubBinary.Url;

        if (pubBinary != null)
            publishPath = pubBinary.Url;
    }

    return publishPath;
}   

  1. Create the Strong-name and add it to the GAC using the gacutil.exe.

  2. Edit your environment Tridion.ContentManager.config and find the element and inside it, the element. Add your class dll reference.

    <tridion.templating>
        <functionSources>
            <functionSource type="YourCompany.Tridion.Templating.YourCustomClassExtensions" assembly="MyCustomClass, Version=1.0.0.0, Culture=neutral, PublicKeyToken=ddfc8957d6e5ee6b" />
        </functionSources>
    </tridion.templating>
  1. Restart SDL Tridion services and COM+

  2. In your TBB Razor template, you can call your template callable function as below

    @{ 
         var dw = new YourCompany.Tridion.Templating.YourCustomClassExtensions();
         dw.Initialize(TridionHelper.Engine, TridionHelper.Package);  
    }
    
    @dw.PublishBinary(cp.Component.Fields.Media.Id)
    

I hope it helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.