2

I have a component source xml as below:

<image_227x140>
    <img style="width: 227px; height: 140px;" alt="alttext" title="IA_Offer2" xlink:href="tcm:382-26496" xmlns="http://www.w3.org/1999/xhtml" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:title="IA_Offer2"></img>

I need the output of my dwt template to be as below:

<img src="folder1/folder2/image.gif" alt="alttext" />

Is there a way to do this in without using the Get extension?

Background information: The image is a multimedia component which is inserted into an RTF field. image_227x140 is the RTF field name.

Right now, not sure how to render the desired output format. If I render with something like this:

<img src="@@image_227x140@@" alt="@@image_227x140.Metadata.alternative_text@@"/>

It is giving the output as:

<img src="tcm:0-0-0" width: 227px; height: 140px;" alt="alttext" title="IA_Offer2" />" alt=""/>

The requirement is to use a RTF field, that's why trying to find a way.

3
  • What is the current output of your RTF field? as I would expect a DWT TBB to already correctly output it (somewhat) like this. Also you could consider to use a Multimedia Link rather than a RTF field and construct the image tag all by yourself in your DWT TBB. Commented Jun 12, 2014 at 11:50
  • Right now, not sure how to render the desired output format. If I render with something like this <img src="@@image_227x140@@" alt="@@image_227x140.Metadata.alternative_text@@"/> it is giving the output as <img src="tcm:0-0-0" width: 227px; height: 140px;" alt="alttext" title="IA_Offer2" />" alt=""/> And the requirement is to use a RTF field, that's why trying to find a way.
    – Keirthana
    Commented Jun 12, 2014 at 12:09
  • Is the field currently a Rich Text Format area and not a Multimedia link? Using the field name wouldn't work as it would be an anchor instead of a TCM URL, right? Do you have the Default Finish Actions TBB to add images to the package and resolve links? Also, in a rich text field, inserting an image allows authors to add their own alternative text (which is technically where alt text should go--in the context of the linking component, though alt text in the Multimedia component can be a good default value). You might want to handle (or ignore) any alt text authors add as well. Commented Jun 12, 2014 at 15:13

1 Answer 1

4

Is your main challenge to make the Alt attribute come from the Multimedia component's metadata field or to simply output an images that are added to RTFs?

If the latter, then simply output the RTF in DWT @@myRTF@@. Tridion will take care of outputting the image tag correctly, and Editors can specify the Alt text for the image as they insert it, directly in the advanced properties dialog. enter image description here

If the former, then you may want to add a TBB at the beginning of your template which would parse the RTF html and identify each img tag which starts with "img src="tcm:" using a Regular Expression. Then load the metadata fields of the image to extract the Alt text and replace the Alt text with the correct value. Note that this will replace the default product behavior so Editors need to be informed that they should only specify the Alt text of images in the MM component metadata instead of using the advanced options in RTF (see image above).

Your Answer

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

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