8

I have a schema with a multi-valued embedded field, which further have multi-valued text field. Need to loop through the embedded field first and then loop through the multi-valued text field - using XPM tags.

I have read the documentation of XPM where FieldStartMarker fields and its use has been described, but not able to get it work for this scenario.

Component Name: Header
-- Multi-valued Embedded Field: contact_us
---- Single text field: title
---- Multi-valued field: contactnum

Following is the component source XML:

<header>
  <contact_details>
    <title>Title1:</title>
    <contactnum>123456</contactnum>
    <contactnum>234567</contactnum>
  </contact_details>
  <contact_details>
    <title>Title2:</title>
    <contactnum>123456</contactnum>
    <contactnum>234567</contactnum>
  </contact_details>
  <contact_details>
    <title>Title3:</title>
    <contactnum>444555</contactnum>
  </contact_details>
</header>

For title (single text field), the following markup is working fine:

<!-- TemplateBeginRepeat name="contact_details" -->
@@FieldStartMarker("contact_details[${TemplateRepeatIndex}].title")@@
    @@FieldValueStartMarker()@@
      @@GetFieldValue("contact_details[${TemplateRepeatIndex}].title", 0)@@
    @@FieldValueEndMarker()@@
@@FieldEndMarker()@@
<---- here one more TemplateBeginRepeat, to loop through contactnum, with XPM tags ---->
<!-- TemplateEndRepeat -->

Inner loop i'm trying (which is not working) is as below:

  @@FieldStartMarker("contact_details[${TemplateRepeatIndex}].contactnum")@@
     <!-- TemplateBeginRepeat name="contact_details[${TemplateRepeatIndex}].contactnum" -->
         @@FieldValueStartMarker(TemplateRepeatIndex)@@
            @@GetFieldValue("Field.contactnum", TemplateRepeatIndex)@@
         @@FieldValueEndMarker()@@
     <!-- TemplateEndRepeat -->
  @@FieldEndMarker()@@

Please help me out to put correct markups. Here I need to make sure inline editing for "title" field as well, and then the multi-value contactnum field.

EDIT(1):

I have tried putting the following markup:

@@FieldStartMarker("contact_details")@@ <!-- TemplateBeginRepeat name="contact_details" --> <div> <h4> @@FieldStartMarker("contact_details[${TemplateRepeatIndex}].title")@@ @@FieldValueStartMarker()@@ @@GetFieldValue("contact_details[${TemplateRepeatIndex}].title", 0)@@ @@FieldValueEndMarker()@@ @@FieldEndMarker()@@ </h4> <p> @@FieldValueStartMarker(TemplateRepeatIndex)@@ @@FieldStartMarker("Field.contactnum")@@ <!-- TemplateBeginRepeat name="Field.contactnum" --> <span> @@FieldValueStartMarker(TemplateRepeatIndex)@@ @@GetFieldValue(FieldPath + ".contactnum", TemplateRepeatIndex)@@ @@FieldValueEndMarker()@@ </span> <!-- TemplateEndRepeat --> @@FieldEndMarker()@@ @@FieldValueEndMarker()@@ </p> </div> <!-- TemplateEndRepeat --> @@FieldEndMarker()@@

But it is throwing an error:

(80040801) FieldStartMarker does not have a FieldEndMarker.

EDIT(2) The error has been resolved by putting the following markup.
@@FieldStartMarker("contact_details")@@ <!-- TemplateBeginRepeat name="contact_details" --> <div> @@FieldStartMarker("contact_details[${TemplateRepeatIndex}].title")@@ @@FieldValueStartMarker()@@ @@GetFieldValue(FieldPath + ".title", 0)@@ @@FieldValueEndMarker()@@ @@FieldEndMarker()@@ <p> @@FieldValueStartMarker(TemplateRepeatIndex)@@ @@FieldStartMarker("contact_details[${TemplateRepeatIndex}].contactnum")@@ <!-- TemplateBeginRepeat name="Field.contactnum" --> <span> @@FieldValueStartMarker(TemplateRepeatIndex)@@ @@GetFieldValue(FieldPath + ".contactnum", TemplateRepeatIndex)@@ @@FieldValueEndMarker()@@ </span> <!-- TemplateEndRepeat --> @@FieldEndMarker()@@ @@FieldValueEndMarker()@@ </p> </div> <!-- TemplateEndRepeat --> @@FieldEndMarker()@@

However, inline editing is still not enabled. Title and contact num are rendering properly, but not editable in XPM.

The following HTML markup is published to the page,

<div>
<span><!-- Start Component Field: {"XPath":"tcm:Content/custom:header/custom:contact_details[1]/custom:title[1]"} -->
Customer service:
</span>
<p>
<span><!-- Start Component Field: {"XPath":"tcm:Content/custom:header/custom:contact_details[1]"} -->
    <span>
        <span><!-- Start Component Field: {"XPath":"tcm:Content/custom:header/custom:contact_details[1]/custom:contactnum[1]"} -->
            (+46) 0123456789
        </span>
    </span>
    <span>
        <span><!-- Start Component Field: {"XPath":"tcm:Content/custom:header/custom:contact_details[1]/custom:contactnum[2]"} -->
            (+46) 0123456789
        </span>
    </span>
    <span>
        <span><!-- Start Component Field: {"XPath":"tcm:Content/custom:header/custom:contact_details[1]/custom:contactnum[3]"} -->
            (+46) 0123456789
        </span>
    </span>
</span>
</p>
</div>

Please let me know if I am missing any tag here. Also, please confirm if the XPath is correct,
"XPath":"tcm:Content/custom:header/custom:contact_details[1]/custom:title[1]",

  • Are your schema fields set to be inline editable? – Alvin Reyes Jul 30 '14 at 1:44
  • Yes, they are set as inline editable.. all of them contact_details, title, contactnum – Saurabh Mehndiratta Jul 30 '14 at 4:14
  • Gotcha!! There's something wrong with the HTML that I have around it.. On a test page (with no other HTMLs), the above markup is working fine.... I am able to edit all of these fields in XPM.. thanks a lot for your help Alvin.. :) :) – Saurabh Mehndiratta Jul 30 '14 at 4:31
  • 1
    Good to hear and thanks for sharing a good, working example of the 2013 SP1 markup. :-) – Alvin Reyes Jul 30 '14 at 5:13
  • HTML is also fine, since the component is the 1st on the page (header component).. thus the "lock" symbol is not appearing. I provided some margin-left, margin-top via chrome developer tools in the HTML and then able to unlock the component.. Is it possible to give this margin to the span of component presentation XPM tags permanently so that we can see the lock symbol properly for all components...?? – Saurabh Mehndiratta Jul 30 '14 at 5:43
4

I understand Tridion 2009 added the FieldPath variable to help handle multi-value embedded fields. For reference see https://stackoverflow.com/q/10309577/395495 and Frank van Puffelen's explanation on how this worked in the Tridion Cookbook Example.

For the new XPM markup, though the methods have changed (and RenderComponentField has been deprecated), you can (probably should) still use FieldPath to reference embedded multi-value fields.

The example from SDL Live Content (requires login) has:

  • Multi-valued Embedded Field: body
    • Multi-valued field: section

XML:

<Content xmlns="uuid:8841d68e-7b1b-45cd-a6d6-7e7da5de3ef9">
    <body>
        <section>Blue section</section>
        <section>Green section</section>
    </body>
    <body>
        <section>Yellow section</section>
        <section>Red section</section>
    </body>
</Content>
@@FieldStartMarker("body")@@
  <!-- TemplateBeginRepeat name="body" -->
    @@FieldValueStartMarker(TemplateRepeatIndex)@@
      @@FieldStartMarker(Field.section)@@
        <!-- TemplateBeginRepeat name="Field.section" -->
          @@FieldValueStartMarker(TemplateRepeatIndex)@@
            <div>@@GetFieldValue(FieldPath + ".section", TemplateRepeatIndex)@@</div>
          @@FieldValueEndMarker()@@
        <!-- TemplateEndRepeat -->
      @@FieldEndMarker()@@
    @@FieldValueEndMarker@@
  <!-- TemplateEndRepeat -->
@@FieldEndMarker()@@

I see two differences between the documentation and your example:

  1. For FieldStartMarker() you have TemplateRepeatIndex in the second, multi-value call, though I believe TemplateRepeatIndex would still refer to the outer loop (as it did with the old markup).
  2. You have "Field.values" instead of using FieldPath as in: @@GetFieldValue(FieldPath + ".section", TemplateRepeatIndex)@@.

Another article with the same example gives the same tip as Frank:

"For extra clarity, while developing your template code, be sure to output the values of FieldPath and TemplateRepeatIndex at the top of every loop with a statement such as: (FieldPath=@@FieldPath@@, TemplateRepeatIndex=@@TemplateRepeatIndex@@)"

Maybe add this check to help troubleshoot as well as your outer loop and output to make it clearer what your markup is doing. :-)

  • Thanks Alvin, I tried this approach (edited and added in the question above).. but doesn't work in my scenario.. please have a look, let me know if there's anything wrong in the markup.. thanks :) – Saurabh Mehndiratta Jul 29 '14 at 5:11

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.