Relative path handling in SDL Tridion - tridion

In SDL Tridion, Dreamweaver template, I have to set a relative path to my image in Page Template.
Tridion produces output as below when I do have code like this in DWT.
DWT Markup
<img src="##Field##"/>
Template Renders
<img src="image.jpg"/>
However when I add a relative path like this, the template returns tcmid
DWT Markup
<img src="Folder/img/##Field##" type="text/css" rel="stylesheet"/
Template Renders
<img src="tcm:8-674"/>
And this causes images not being presented properly in website. I tried with Tridion type: multimedia etc, but nothing has worked so far.
Has anyone seen a similar issue before?

The behaviour you experience is that Tridion (the Dreamweaver mediator) will interpret your src image attribute as WebDAV path of an item in the Content Manager. So if it finds a Multimedia Component under Folder/img/##Field##, it will replace your path with the TCMURI of that Multimedia Component. That's expected behaviour.
However, I don't think that's what you are trying to do (it's not clear from your question). Is your image in Tridion as a Multimedia Component? Are you trying to show this image? Then you should use Multimedia Links (i.e. links to a Multimedia Component) in your DWT: <img src="##Compoennt.Fields.link_to_mmc##"/>, where field link_to_mmc is a Multimedia Link field defined in your Schema. Use then also the 'Resolve Links' Default TBB to convert the TCMURI into a relative image path.
If you are linking to an external image, then you need to specify the URL of that image in your DWT template. Something like this <img src="##Component.Fields.external_url##"/>, where external_url is a Text field in your Schema and it contains the actual URL of the external image you want to show.

It seems like you are almost there, only when you add the string as a relative path, the default TBBs don't recognize the uri held in the SRC attribute anymore. If you are trying to publish the binary to a different location, you will need to bind it to a different Structure Group, alternatively try changing the multimedia URL on your publication. that way the images will be published (and resolved) to you sub directory.

If your imagefields field is a link to a Multimedia Component, then all you need is <img src="##Field##"/>. With that Tridion will (in this order):
replace the ##Field## with the TCM URI of the image (e.g. tcm:6-874) when it executes the DWT
put the image item into the package as an implicit step after executing the DWT
publish the images (as one of the steps in the Default Finish Actions)
replace the TCM URI (tcm:6-874) with the path of the published image
Since you'll probably have custom TBBs between the DWT and the Default Finish Actions, you could use those to modify the image item and influence what gets published (and where, using item properties).
If you've set up your Tridion installation correctly, you'll typically store the base path to the images in the Publication properties and then step 3 just puts the the image in there and step 4 puts the full path (including what you specified in the Publication properties) into the HTML.
If you want more control over the relative path, the Publish Binaries in Package and Default Finish Actions TBBs have a parameter that allows you to specify to which Structure Group the images will be published. That way you can have different templates output their images to different Structure Groups/directories on disk.
For the ultimate in control you can also decide to publish the binaries yourself. In that case have a look at the source of the Publish Binaries in Package TBB (available from the forum on SDL Tridion World), modify it to suit your needs and replace the one in Default Finish Actions with your modified version.

Related

How can we save multimedia components using external resource types if the URL doesn’t end in with a file extension?

We have a Tridion use case related to curated content where we are creating multimedia components for images associated with our content which are pointing to External resource types instead of uploaded resource types.
One of the issues we have run into with this use case is that despite explicitly setting the Multimedia Type for the resource, if the URL of the image has either a query string in it: http://cdn.hw.net/UploadService/1c8b7f28-bb12-4e02-b888-388fdff5836e.jpg?w=160&h=120&mode=crop&404=default or uses a ‘friendly url’: http://www.somewhere.com/images/myimage/ when we save the component, Tridion barfs with error messages similar to : ‘Invalid value for property 'Filename'. Unexpected file extension: jpg?w=160&h=120&mode=crop&404=default. Expecting: jpg,jpeg,jpe.’
So far, the only way we’ve been able to figure out to potentially get around this issue is to do something hacky like appending an extra query string parameter to the very end of the urls which end with the expected file extension: http://cdn.hw.net/UploadService/1c8b7f28-bb12-4e02-b888-388fdff5836e.jpg?w=160&h=120&mode=crop&404=default&ext=.jpg Obviously, this is not the best solution and in fact may not work for some images if the site they are being served from strictly validates the requested URL.
Does anyone have any ideas on how we can work around this issue?
Unfortunately I can't really think of an easy solution to this, since Tridion "detects" the Mime type by checking the file extension.
You could perhaps add it while saving and remove it when reading (via Event System)? Definitely a worthwhile enhancement request, to my knowledge this behavior has not been changed for the soon-coming Tridion 2013... See comment below, it has been changed for 2013.
+1 for Nuno's answer. Recognizing that the title of your question is specific to multimedia components, you may want to consider another approach which is to use normal Components, not Multimedia Components. You can create a normal component schema called something like "External Image" that has an External Url field to store your extentionless url.
Content authors will then include these images via regular component linking mechanisms in the Tridion GUI.
You will then need a custom link resolver TBB that will parse the Output item (via Regex) looking for any Tridion anchor tags <a tridion:href="tcm:x-y-z"> and for each one replace them with an <img src=...> tag where the src path would come from this linked component.
For an example of a similar approach, but with videos, and sample code for a custom link resolver TBB have a look at the code in the following post: http://www.tridiondeveloper.com/integration-sdl-tridion-jw-media-player.

Need help to create component template using Template building block

I need help with following scenario:
I have page template PT1 , which contains 2 TBBs and I have component template CT1, which contains 1 TBB.
I created a page using the Page Template(PT1) and added a component and selected the component template (CT1).
The TBBs pushing some text value to package and all three TBB are part of a single dotnet assembly and implemented in three different class, which is implementing "Itemplate" interface and implement "transform" method.
Problem:
In the published file i am able to see the content pushing by TBB used in Page Template PT1, but not able to see content which is pushing by TBB of Component Template CT1.
Typically, to output from a template you need to create a DWT TBB unless you are directly sending Output from C# TBB.
In your case, looks like you have all C# TBBs and are they outputting anything to the package. If not then I even doubt your PT will output any html.
You could use the Template Builder tool to debug your out of the template as in my comments the doc portal link will provide you guidance.

Tridion 2009 SP1: Image Thumbnails - How to publish the original image as well?

I have a Dynamic Component Template which publishes XML to the Broker database which is then dynamically loaded using the Component Presentation factory.
This Xml contains URLs to Images. I need a thumbnail and a full image to be available. I have managed to use the Image Resizer TBB to produce the thumbnails however, I was hoping that this would add separate package items and binaries that could be referenced, but it seems to overwrite the full size images.
Is there a way I can get both into my Xml and the Package without writing my own custom TBB?
Tridion Content Delivery can store multiple variants of the same Multimedia Component. Each such variant has an ID that identifies it and the variant with no ID (of in newer versions #def# as its ID) is known as the default variant.
When you reference an image from a DWT, it is automatically added as an item to package when the render engine executes your DWT. This item is then later processed by the default "Publish Binaries in Package" TBB that is part of the Default Finish Actions. The Publish Binaries in Package TBB publishes binaries by calling AddBinary on them - you can verify this by looking at the original code for most default TBBs that was published on the Tridion forum here (login required).
appliedTemplateUri = new TcmUri(item.Properties[Item.ItemPropertyTemplateUri]);
...
engine.AddBinary(itemUri, appliedTemplateUri, targetStructureGroup,
data, fileName);
The AddBinary method that is called is defined in the TOM.NET CHM as:
public abstract string AddBinary(
TcmUri componentUri,
TcmUri templateUri,
TcmUri targetLocation,
byte[] data,
string fileName
)
componentUri
The multimedia component this item refers to
templateUri
The template in whose context this AddBinary call is executed (used as variant id)
targetLocation
The location to publish the binary to (if null, publish to standard path)
data
The binary data to publish
fileName
The filename to publish the file under
So as you can see in that last call to AddBinary, the Publish Binaries in Package TBB uses a property (look here if you've never heard of Item.Properties) to determine which variant to publish (and publishes the binary as the default variant if the property is not present).
With all this knowledge in hand, the task becomes quite simple: you have to ensure that there are two binary Items in the package for your MMC, each with a different value of the Item.ItemPropertyTemplateUri property.
The default Image Resizer TBB replaces the binary content of the Item it resizes and does not set this property. So the least code you'll have to write is either a pre-processor TBB that duplicates the item or a post-processor TBB that re-adds the item. In both cases the TBB will have to set the "magic" property too.
Useful links:
the original C# source code of the default template building blocks
a page describing Item.Properties and how to see what they do in your compound template
a recent post on the SDL Tridion forum about the same topic (login required)
Basically all the Image Resizer TBB does is resize the image already in package, so the Default Finish Actions TBBcan publish it (using an AddBinary() call).
So what you require is a slight change in the logic of the Resizer TBB (you need to do something yourself here), so that it does not resize the original item in the package, but publishes a variant of it. Then you have two images available on the delivery side (you can distinguish them by sending the resized image to a different structure group for instance).

How can I use flash files in my SDL Tridion page?

My page is showing regular component presentations very well.
I have a flash/video file in my local machine and i want to upload this file on my page.
How can I achieve this?
I have this code snippet for rendering components on my page:
<!-- TemplateBeginRepeat name="Components" -->
<!-- TemplateBeginIf cond="ComponentTemplate == 'HomePageCT'" -->
##RenderComponentPresentation()##
<!-- TemplateEndIf -->
<!-- TemplateEndRepeat -->
Please provide all details related to flash files and video files.
Placing a Flash file on a page follows exactly the same process as placing any image in the output of your templates. The steps are outlined below:
Create a Multimedia Schema which allows the Flash multimedia type (e.g. Flash Video Schema)
Upload your Flash file using your new Schema
Create a Component Template to render the HTML you want to use to display the Flash file, and actually publish the binary itself. (e.g. Display Flash CT)
Create a page template (you seem to have done this part) which renders the Page, and renders the Components on the page using ##RenderComponentPresentation()##
Create a Page, and place your Flash file on it using the Display Flash CT
Publish the Page
Without details of the output you want to produce, it is hard to provide the sample Dreamweaver Template Building Block code for the DisplayFlash CT, but it might look something like this:
<embed src="##Component.Id##" allowFullScreen="true" width="540"
height="438" bgcolor="#000000" type="application/x-shockwave-flash"
pluginspage="http://www.macromedia.com/go/getflashplayer">
</embed>
Make sure you use the Default Finish Actions TBB after this in your Component Template so that the src link is processed and the binary is published.
There is nothing special about Flash files with Tridion. They can be treated just like any other Multimedia Component. You can upload them into the CME (or by using Webdav) and thus you will have a Multimedia Component. Make sure of course, that you Multimedia Schema allows the Flash (and extension) as Multimedia Type.
Regarding how you put the Flash file on the Page - again just like a normal Multimedia Component. In your CT you have to generate the output that will make use of your Flash file URL somewhere. You will have to publish your Flash MMC in order to get its URL. You can use Engine.AddBinary or RenderedItem.AddBinary methods for that, or use the Publish Binaries in Package Default TBB, if your MMC is in the package. Then you can simply refer to your Flash URL as package item. Have a look at this URLs for some inspiration: http://yatb.mitza.net/2012/03/publishing-images-as-variants.html (your case doesn't have to be that complex) and http://yatb.mitza.net/2012/04/referencing-image-variants-from.html.
There are several approaches to rendering Multimedia with a Tridion-managed page.
Multimedia components can be:
Part of a component presentation, added to a page with a template selected
As a linked-to multimedia component within a "container" component, which is added to a page
In a rich text format (RTF) area within another component
You could also just publish binaries with dynamic component templates and handle the markup and links outside of Tridion. Get creative with the above basic scenarios depending on the markup and/or metadata you need.
Chris addresses #1 and Mihai explains schema setup and .AddBinary. The second option would be similar, except you'd have to get the referenced ID rather than the component on the page. The third option requires you to parse multimedia within RTF which depends on your templating language and multimedia type.
I've seen XSLT (<xsl:template match="">), grep, and various .replace options to parse specific markup such as Flash videos.

Getting URL of published element in SDL Tridion

Is there any way of finding the absolute URL for a published object in the SDL Tridion Interface?
For example when I published a page, how can I find the url where to access the page?
Though not finished, and not really very documented, the Tridion 2011 PowerTools includes 2 buttons to "Open in Staging" and "Open in Live".
If you're looking for the code in your c# tbb library you can use the PublishLocationUrl property for pages and structure groups:
StructureGroup.PublishLocationUrl or
Page.PublishLocationUrl
This will return the URL if the item is published or not, as Page and StructureGroup extend the ReposityObject class, I typically perform a check to see if the ReposityObject is published to the target that the Page is being published to for example:
if (PublishEngine.IsPublished(myReposityObject, myEngine.PublishingContext.PublicationTarget))
{
// page or sg is published!
}
Note: Where the myEngine is an instance of the Engine object.
If you're doing this in the core service, that's a little different, what you need to do is create a PublishLocationInfo object which is casted from your Page or StructureGroup object property LocationInfo, as shown below:
PublishLocationInfo pubInfo = (PublishLocationInfo)page.LocationInfo;
return pubInfo.PublishLocationUrl;
It is not very straightforward, mostly because Tridion allows you to publish a single page to multiple targets (= web sites). The page could in fact have a number of URLs.
However, the best option is to open the page and click on the Info tab. There you will find the File Path, which might look like this: \about\press\2011. Replace the backslashes with slashes, and add the page's filename and file extension (can be found on the General tab). Put the whole thing behind the root URL of your web site (e.g. http://www.mysite.com').
Tridion exposes the path of the URL in PublishLocationUrl property. You can access this either through the TOM.NET API or by viewing the raw XML of the item by entering the TCMURI in the address bar of Internet Explorer (e.g. tcm:4-264-64).
But in either case those will just return the path part of the URL. You'll have to prefix it with the correct base URL as Quirijn already mentioned earlier.
In the past, I have resorted to extending the protocol schemas for publication target destinations. Having added a baseURL property there, I could access this from events system code (the idea was to mail a link to a workflow approver).
These days, you could use application data to do the same thing.

Resources