I've been struggling to find clear documentation on implementing Experience Manager fields <tcdl:Field><tcdl:FieldValue></tcdl:FieldValue></tcdl:Field> into Razor C# template building blocks. Using them on basic content has been no problem, but I've got a template that has repeating fields and repeating embedded fields and cannot figure out the proper syntax and how to implement those fields.

First, sample data structure:

<Content xmlns="uuid:78c66fc7-8125-4c9f-ab84-1ca272daa30b" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="uuid:78c66fc7-8125-4c9f-ab84-1ca272daa30b http://...../Project%20Log.xsd">
        <Developer>Joe Blow</Developer>
            <WorkDescription>header formatting</WorkDescription>
            <WorkDescription>footer formatting</WorkDescription>
        <Developer>Jane Doe</Developer>
            <Category>User support</Category>
            <WorkDescription>SA work</WorkDescription>

Here is my Template Building Block file:

  int grandTotal = 0;
  int index = 0;

  @foreach (var developers in @Component.Fields.DeveloperLog ) 
    int sumTotal = 0;
      <span class="fa fa-user"></span> 
    <table class="table table-striped table-bordered table-hover">
          <th>Work Order # (optional)</th>
        @foreach (var workItems in @developers.WorkLog) 
            <td> <span>@workItems.Date</span> </td>
            <td> <span>@workItems.Hours</span> </td>
            <td> <span>@workItems.Category</span> </td> 
            <td> <span>@workItems.WorkDescription</span> </td> 
            <td> <span>@workItems.WorkOrderNumber</span> </td>
          sumTotal = sumTotal + Convert.ToInt32(@workItems.Hours);
          grandTotal = grandTotal + sumTotal;
          <td colspan="5">Developer&apos;s total hours: @sumTotal </td>
<p>Total hours: <span id="total-hours">@grandTotal</span></p>

I tried, just as a proof of concept to try and work out the first field, Developer, and this is the tags that I put around @developer.Developer

      <tcdl:Field xPath="tcm:Content/custom:Content/custom:DeveloperLog/custom:Developer" index="@index" itemId="@Component.Id">
        <tcdl:FieldValue index="@index">

Experience Manager aside, everything outputs as expected. Where I run into problems is with Experience Manager. The first field set (where Joe Blow outputs) works as expected and can change the field value with Experience Manager. However the second instance of that field does not. I thought that the required an index on it to differentiate itself from the others, but that seemed to not make a difference.

What is the syntax for handling repeating and embedded repeating fields? For consideration, I'm not using Dreamweaver TBBs, so the DW TBB documentation doesn't help. Additionally the documentation here is unclear.

  • For what it's worth, I've tried this as well: <tcdl:Field xPath="tcm:Content/custom:Content/DeveloperLog[@index]/Developer" itemId="@Component.Id"> <tcdl:FieldValue index="@index"> @developer.Developer </tcdl:FieldValue> </tcdl:Field> ...and that didn't work at all. I found this old documentation from 2013 — docs.sdl.com/LiveContent/web/… — and tried to follow that, but still isn't working.
    – michael t
    Dec 11, 2019 at 14:15


Your Answer

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

Browse other questions tagged or ask your own question.