2

Could anyone help to enable SiteEdit for ComponentLink Fields in DD4T?

I am fine with direct and embedded fields.

For component link fields, I am trying like below. But this is not working for me.

Fields are provided for Inline Editing.

var linkedcomponents = Model.Fields["FieldName"].LinkedComponentValues;
for (int counter = 0; counter < linkedcomponents .Count; counter++)
{
  var complinks = Model.Fields["FieldName"].LinkedComponentValues[counter];
  MvcHtmlString Desc = MvcHtmlString.Empty;
  Desc = complinks.Fields["FieldName"].Value.ResolveRichText();
  <span>  
        @Html.SiteEditField(Model, complinks.Fields["FieldName"])@MvcHtmlString.Create(Desc.ToString()) 
  </span>
}
  • Can you edit the question and add the outcome of the rendered page (the HTML source) from this field with the SiteEdit markup (so view the source of the page before entering SiteEdit/XMP)? – Bart Koopman Aug 2 '13 at 7:30
2

This is not an easy thing to do.

If you look at how SiteEdit structures its data, you'll see the following pattern:

Page ID
 Component ID/Template ID
  Field
  Field

What you're trying to do is to tell SiteEdit to edit a field, but that field cannot be found in the current component context, so there's no way it can identify which field you're working on.

To do what you want you'd need to structure the data like this:

Page ID
 Component ID/Template ID
  Field
  Component ID/Template ID
   Field
  Field

You'd have to provide the markup yourself for the "linked" Component presentation, and you would have to "fake" a Template ID - hint, you could use the same Component Template ID. You will also have to mark the fake Component Presentation as "IsDynamic", otherwise SiteEdit will complain that it cannot find the component presentation within that page (which is technically correct).

1

I think for starters you need to specify which index of the field you want editable, so add the counter to your SiteEditField call:

@Html.SiteEditField(Model, complinks.Fields["FieldName"], counter)

I'm not sure if the counter in the DD4T extension method is zero or one based, but that should be easy to find out.

  • Bart, I have tried that by adding the counter, it doesn't help. – Jey Aug 1 '13 at 12:16
  • so what exactly is going wrong? in your question you just mention it is not working for you, please elaborate (edit your question and add more details like error messages etc.) – Bart Koopman Aug 1 '13 at 12:56
  • Bart, when i click the particular area after providing the third parameter (counter), the entire text goes away from the site edit box... – Jey Aug 2 '13 at 5:52

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.