Sitecore: How to access same field name in differe

2019-03-25 12:11发布

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

标签: sitecore
4条回答
我命由我不由天
2楼-- · 2019-03-25 12:44

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
    }
}
查看更多
老娘就宠你
3楼-- · 2019-03-25 12:51
item.Fields.Where(field => field.Section.ToUpper() == "META DATA" && 
                           field.DisplayName.ToUpper() == "TITLE").First().Value;
查看更多
一夜七次
4楼-- · 2019-03-25 12:52

You can't.

And frankly I don't know of any supported way to do it from .NET either.

This, straight out of the Data Definition Reference, section 2.1.1

2.1.1 Data Template Fields

A data template field defines the user interface control and other properties that influence how the field behaves in the Content Editor and Page Editor. For more information about fields, see Chapter 4, The Template Field.

Note When defining field names, ensure that they are unique even between field sections. Both XSLT and .NET code use field names alone, without reference to sections, to extract content from fields.

查看更多
The star\"
5楼-- · 2019-03-25 13:07

You can reference fields by their IDs:

C#:

string value = item["{00000000-0000-0000-000000000000}"]

or

Field field = item.Fields["{00000000-0000-0000-000000000000}"]

I haven't tried this, but I think it'll work in XSLT as well:

<sc:text field="{00000000-0000-0000-000000000000}" />

查看更多
登录 后发表回答