7

I'm working on a Razor template to display a kind of samll FAQ section. Each item of this FAQ (composed by a question and an answer in rich text fields) is added to the FAQ list as a component link and I would like to make it inline editable with Experience Manager.

I can make the list itself editable, so an editor can add or remove components and of course, I can make editable the general list fields but, is possible to make the linked component fields also editable?

I have tried with:

@RenderComponentField("componentLinkListField[" + counter + "].question")

And also with:

<tcdl:ComponentField name="componentLinkListField[@counter].question"></tcdl:ComponentField>

And even something like:

<tcdl:ComponentField name="componentLinkListField.question" index="@counter"></tcdl:ComponentField>

And a lot of variants of these examples... But nothing seems to work.

2 Answers 2

2

If I understand your question correctly, then I think that this is covered in the Making subfields of embedded multivalue fields editable section of the online documentation (login required).

Something like the following may work:

@@RenderComponentField("componentLinkListField[${TemplateRepeatIndex}].question", 0)@@

This should produce the following output (for the first question):

<span id="_SE_FLD" _SE_FLD="tcm:Content/custom:Content/custom:componentLinkListField[1]/custom:HouseNumber[1]">

-

Update [27/06/2013]

It looks like this is a known issue. For example, some additional functions are given on the Tridion Practice site here.

It appears that there is a workaround for this that allows you to output the necessary Experience Manager / UI code (a HTML comment used on the front-end) just above the field that you want to make editable. E.g.
<!-- Start Component Field: {{'ID' : 'tcm:99-1234', 'XPath' : 'tcm:Content/custom:Content/custom:question[1]'}} -->

To do this you could write a Razor Helper Function that takes the tcmId of the Component and the name of the field. E.g.

@helper OutputComponentLinkXmCode(string fieldName, string componentTcmId) {
   IdentifiableObject component = TridionHelper.Engine.GetObject(componentTcmId);
   @String.Format("<!-- Start Component Field: {{'ID' : '{0}', 'XPath' : 'tcm:Content/custom:Content/custom:{1}[1]'}} -->", component.Id, fieldName);
}

You could then call this as follows:

@for (int i = 0; i < Fields.componentLinkListField; i++) {
    <div class="question">@OutputComponentLinkXmCode("question",@componentLinkListField[i].ID)@Fields.componentLinkListField[i].Fields.question</div>

    <div class="answer">@OutputComponentLinkXmCode("answer",@componentLinkListField[i].ID)@Fields.componentLinkListField[i].Fields.answer</div>
}

I think that the field has to be wrapped in an outer HTML element (hence the Div in the code sample).

You could also extend the Razor function to multivalued fields (in the inner Component) by passing in the index (currently hardcoded to [1]).

This also assumes that the Root Element of your inner Q&A Component is still Content too.

5
  • Thanks Jonathan, but in this scenario the field is not an embedded field but a Component Link one, with multivalue allowed.
    – glezalex
    Commented Jun 27, 2013 at 12:58
  • Ah, yes. I have updated my answer. Commented Jun 27, 2013 at 20:16
  • Looks awsome, thanks! I will give it a try as soon as I can.
    – glezalex
    Commented Jun 28, 2013 at 10:45
  • Unfortunately, doesn't seem to work. Writing out '<!-- Start Component Field: {{'ID' : 'tcm:0-00-0', 'XPath' : 'tcm:Content/custom:Content/custom:question[1]'}} -->' (as a generic example) results in the Experience manager UI obviating the ID parameter and searching for a question field in the current component instead of the linked one. I will continue digging on it...
    – glezalex
    Commented Jun 30, 2013 at 9:17
  • What happens if you hardcore the tcmId? Does UI still ignore it? Commented Jun 30, 2013 at 15:24
1

Thanks Jonathan for your time.

We have just contacted SDL and for now it's not possible. I missed a detail, we are working with Tridion 2013 and looks like this feature will be delivered for SP1.

1
  • No problem. I guess that it is the {'ID' : '{0}', part that isn't implemented for 2013 yet. It may be worth noting that this solution should work for Tridion UI Update for 2011. I have updated the tags on your question. Commented Jul 4, 2013 at 10:40

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.