Take the 2-minute tour ×
Tridion Stack Exchange is a question and answer site for Tridion developers and administrators. It's 100% free, no registration required.

I am using tridion 2013, where I need to publish the css images. It's getting published using the below templates(1 & 2) but is appending the tcm id.

Template 1 - I thought using Addbinary would not append the tcmid but it's doing so.

Component mmc = engine.GetObject(package.GetValue("Component.ID")) as Component;
engine.PublishingContext.RenderedItem.AddBinary(mmc);

Template 2 -

TcmUri Comp = new TcmUri(package.GetValue("Component.ID"));
Item compItem = package.CreateMultimediaItem(Comp);
package.PushItem("MultimediaDoc"+compItem.ToString(),compItem);

Now if I need to directly refer that image in the PT/CT like "images/print.css" instead of reading from the component then it's not appearing since the filename is not matching(in PT it's without tcm id and I can't use it because of environment conflict). Please suggest how to refer it correctly in my page even if it's published with tcm id appended.

UPDATE - I have used the same DFA along with Template 2 code to publish the binary in
2011, it gets published without tcmid, but in 2013 only it's appending tcmid.

share|improve this question
    
can you expalin why do you have 2 TBBs for it? also, are you using "Default finish actions" TBB in your template? –  Saurabh Gangwar Apr 23 at 12:06
    
I have tried with both one by one to see if it gets published without tcmid, but both are having the same output. Yes I have DFF having the inbuilt Publish Binary in Package TBB. –  user945 Apr 23 at 12:12
    
The "Publish binaries in package" TBB, which is a Part of DFA Tbb. it could add the TcmID to the filenames to avoid conflict between the binaries having the same title. I suggest you to try Template 1 without it. –  Saurabh Gangwar Apr 23 at 12:21
    
How the images will then get published to the server after removing "Publish binaries in package" TBB? –  user945 Apr 23 at 13:01
    
The engine.PublishingContext.RenderedItem.AddBinary() function will do it for you, Please refer TOM.NET API document for more details and overloaded methods for it. –  Saurabh Gangwar Apr 23 at 13:19

2 Answers 2

What you are doing in your Template 1 is publishing the Multimedia Component using the RenderedItem.AddBinary() method. However you don't seem to be doing anything with the Binary object returned (which contains the Binary.Url property).

Then in Template 2, you are also adding your Multimedia Component to the package, after which the "Publish Binaries in Package" TBB will publish it using its AddBinary() method too. And then the "Link Resolver" TBB will use its outcome to resolve the links to your Multimedia Component. So it appears you are processing your item twice, assuming you have the "Default Finish Actions" TBB also in your Template.

Please note that there are several different AddBinary() methods (RenderedItem.AddBinary(), Engine.AddBinary() and TemplatingRenderer.AddBinary()), each have their own specific behavior and overloads. The "Publish Binaries in Package" TBB uses the Engine.AddBinary() method.

I'll leave it up to you to find out which one does or does not add the TCM URI, but one thing is certain, you will always need to do something with the return of the AddBinary() method. Else what you are doing is just publishing the Multimedia Content and you have no way of resolving the links in your original Template.

If you decide to publish the binary yourself, then make sure it is not also done via any other TBB. You can prevent that from happening by setting the published path in the package item properties (Item.ItemPropertyPublishedPath), see the code example below of how that can be done:

foreach (Item item in package.GetAllByType(new ContentType("*/*")))
{
    if (item.Properties.ContainsKey(Item.ItemPropertyTcmUri) &&
        item.Properties.ContainsKey(Item.ItemPropertyFileName))
    {
        // has the item already been published?
        if (!item.Properties.ContainsKey(Item.ItemPropertyPublishedPath))
        {
            // publishing item of type item.ContentType
            string publishedPath = engine.AddBinary(item, targetStructureGroup);

            item.Properties[Item.ItemPropertyPublishedPath] = publishedPath;
        }
    }
}
share|improve this answer
    
Originally I had the template 2, to put the mmc in package and rest of the things i thought will be taken care by the DFA's AddBinary() method. But in my case it's appending the tcmid which is not the case with AddBinary. –  user945 Apr 24 at 8:37
    
@user945 The Default Finish Actions does not append the TCM URI when publishing the MMCs, so if you see that happening, there is something else doing it. It could be something which was added like is described here urbancherry.net/blogengine/post/2010/02/09/… –  Bart Koopman Apr 24 at 14:45
    
With Template 2 and DFA, it's appending tcmid. I have checked it in template builder and template 2 is not appending tcmid and as per you DFA is not appending as well. Why the behaviour is such in 2013 where as 2011 is not appending. –  user945 Apr 25 at 9:11

There is a great article in this blog CSS in SDL Tridion – Part 2: Handling image references in which it seems to suggest what you need to do.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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