4

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">
    <DeveloperLog>
        <Developer>Joe Blow</Developer>
        <WorkLog>
            <Date>2019-12-03T11:54:02.210</Date>
            <Hours>4</Hours>
            <Category>CSS</Category>
            <WorkDescription>header formatting</WorkDescription>
        </WorkLog>
        <WorkLog>
            <Date>2019-12-02T11:54:36.953</Date>
            <Hours>6</Hours>
            <Category>CSS</Category>
            <WorkDescription>footer formatting</WorkDescription>
            <WorkOrderNumber>1234</WorkOrderNumber>
        </WorkLog>
    </DeveloperLog>
    <DeveloperLog>
        <Developer>Jane Doe</Developer>
        <WorkLog>
            <Date>2019-12-03T11:54:57.317</Date>
            <Hours>3</Hours>
            <Category>User support</Category>
            <WorkDescription>SA work</WorkDescription>
        </WorkLog>
    </DeveloperLog>
</Content>

Here is my Template Building Block file:

@{
  int grandTotal = 0;
  int index = 0;

  @foreach (var developers in @Component.Fields.DeveloperLog ) 
  {
    int sumTotal = 0;
    <h2>
      <span class="fa fa-user"></span> 
        @developers.Developer
    </h2>
    <table class="table table-striped table-bordered table-hover">
      <thead>
        <tr>
          <th>Date</th>
          <th>Hours</th>
          <th>Category</th>
          <th>Description</th>
          <th>Work Order # (optional)</th>
        </tr>
      </thead>
      <tbody>
        @foreach (var workItems in @developers.WorkLog) 
        {
          <tr>
            <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>
          </tr>
          sumTotal = sumTotal + Convert.ToInt32(@workItems.Hours);
          grandTotal = grandTotal + sumTotal;
        }
      </tbody>
      <tfoot>
        <tr>
          <td colspan="5">Developer&apos;s total hours: @sumTotal </td>
        </tr>
      </tfoot>
    </table>
    index++;
  }   
}
<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">
          @developers.Developer
        </tcdl:FieldValue> 
      </tcdl:Field>

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 '19 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.