16

I have a component on a page which I am editing using XPM. I am able to edit all of the text fields but I can't change the image that's inside.

The image is not part of a rich text format, it is a standalone multimedia link.

I've read on the internet that "If the image is only one field of a Component (that is, if it sits on the page in a bordered area with other items), the image is replaced with a hyperlink." .

And to change the image - "If the image is a Component field, click the hyperlink. The library slides in on the left.".

Sadly, I have no border around the image (http://screencast.com/t/YK2TPWY41) and when I click it nothing happens, it seems that it is not a hyperlink as it says above.

So, how I am changing an image using the XPM?

14

Basically you need to add the XPM/SiteEdit markup yourself around that image, as you are using additional HTML to display your image (your img element).

So you need something like:

<div>
    <!-- Start Component Field: {"XPath" : "tcm:Content/custom:Content/custom:image[1]"} -->
   <img src="@@Component.Fields.image@@" tridion:type="Multimedia" alt="image" />
</div>

But you can also generate it using the MarkComponentField custom functions as mentioned on Tridion Practice

Then it would look like this in your DWT Template (the outcome will be the same as above):

<div>
    @@MarkComponentField('image')@@
   <img src="@@Component.Fields.image@@" tridion:type="Multimedia" alt="image" />
</div>

The rules for the comment style markup are in the documentation, and you can basically generate it for any type of field, as long as you make sure that there is a parent HTML element around it (in my example the div tag). That element is what the border will follow, so if your HTML doesn't give that specific element the same size as the image (sometimes elements can have a size of 0), then it will be difficult to use/see the border.

Third option is to use the TCDL notification around your field, this will require you to have the Enable inline editing for content TBB in your Component Template after the DWT TBB (similair to what you require when using @@RenderComponentField()@@).

<tcdl:ComponentField name="image">
   <img src="@@Component.Fields.image@@" tridion:type="Multimedia" alt="image" />
</tcdl:ComponentField>

Again this will also end up the same as the first example, but depending on what Default Field HTML Tag you have set in the Parameters of the Enable inline editing for content TBB, you will get that HTML tag around your image (by default a span tag).

Once you get the hang of it, you will notice that a lot more fields are editable in a lot more ways (you can think of editing a link which consists of a url and a title as two different fields, as long as you find a way to put the markup for both of those fields in a separate HTML element). Technically you should only generate this markup on your Staging website, as that is where you use XPM on, but since its an HTML comment, it shouldn't harm your design (if you need to generate extra markers with additional HTML for editing the url and title of a link separately, then that should only happen on Staging and not on Live of course).

Update

It has been brought to my attention that there is an overload available of @@RenderComponentField()@@ with three parameters, which can also give us the wanted result. So option number four reads:

@@RenderComponentField('image', 0, '<img src="${Component.Fields.image}" tridion:type="Multimedia" alt="image" />')@@

Update 2

In 2013 SP1 the RenderComponentField method has been deprecated and is replaced by the following syntax:

@@FieldStartMarker('Component.Fields.image')@@
  @@FieldValueStartMarker(0)@@
    <img src="${Component.Fields.image}" tridion:type="Multimedia" alt="image" />
  @@FieldValueEndMarker()@@
@@FieldEndMarker()@@
  • Thanks, Bart! I used the first way and added the markup by myself and it works now! I also tried with the second way but it fails on publishing and says "Variable MarkComponentField has not been declared". I feel like you know what the problem is, am I right? :) – Stefan Shumanov Apr 9 '13 at 15:08
  • 2
    Yes, the second is a Custom Function, which you still need to declare. The code of that function is available in the link I have placed in my answer. That code should be compiled into a DLL, which you add to the GAC and then register in the Tridion.ContentManager.config. It will make your Templates look cleaner (in my opinion), other than that it's no difference. – Bart Koopman Apr 9 '13 at 15:19
  • Thank, Bart. I will try it tomorrow, I want to make it. :) – Stefan Shumanov Apr 9 '13 at 15:25
  • Check the documentation for how to implement custom functions (requires login), that will clarify my very brief instructions. – Bart Koopman Apr 9 '13 at 16:10
  • 2
    Why not simply use tcdl:ComponentField? <tcdl:ComponentField name="BannerImage"><img src="@@Component.Fields.BannerImage@@" /></tcdl:ComponentField> – Philippe Conil Apr 9 '13 at 17:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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