Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sitecore: How to access same field name in different sections

Tags:

sitecore

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 I have data template dt3 that uses both dt1 and dt2 as base templates.

How can I, in xslt, find the content of portal/header?

In my code, when I write <sc:text field="header" />, I get the content of data/header (since this node comes first). I know how to do this in .net, but I need to use xslt.

/callprat

like image 303
Callprat Avatar asked Apr 24 '09 10:04

Callprat


2 Answers

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<Field> to it
    }
}
like image 132
Dan McClain Avatar answered Nov 21 '22 02:11

Dan McClain


item.Fields.Where(field => field.Section.ToUpper() == "META DATA" && 
                           field.DisplayName.ToUpper() == "TITLE").First().Value;
like image 34
Seth Larson Avatar answered Nov 21 '22 02:11

Seth Larson