Sitecore: How to access same field name in different sections

前端 未结 4 2308
后悔当初
后悔当初 2021-02-14 11:20

I have data template dt1 in sitecore that has the field \"header\" in section \"data\". I also have data template dt2 that has the field \"header\" in section \"portal\" Finally

4条回答
  •  执笔经年
    2021-02-14 11:48

    I found a way around this in .Net on a project I was working on. One of the templates that the client had set up had "Buckets" which had different field sections, but the fields within were the same between buckets. I used LINQ to group the fields by Section name, then dealt with each grouping of fields.

    var sections = currentItem.Fields.GroupBy(field => field.Section);
    foreach (var section in sections)
    {
        if (section.Key.StartsWith("Bucket"))
        {
            buckets.Add(new Bucket(section)); //I made a bucket item, 
                                              //and passed each IGrouping to it
        }
    }
    

提交回复
热议问题