FieldRenderer - Get specific field name from different template sections
Is there a way to get a specific field name from a template with several sections to a FieldRenderer control?
F.ex. I have a template with the sections "Data" and "Data2", both have a single-text-开发者_运维百科field called "Text". Is there a way to make my FieldRenderer get the field "Text" in section "Data2"
It would be nice if one of the below suggestions worked:
<sc:FieldRenderer ID="test" runat="server" FieldName="Text" Section="Data2" />
<sc:FieldRenderer ID="test" runat="server" FieldName="Data2/Text" />
BR Larre
Though it's developed like this on purpose(we don't want Sitecore developers to waste time on section-names), I think it does make sense to include such a thing. Let me list this as a feature request.
If you want to have this working right know, you should first understand how the fieldRenderer is working. It kicks off a pipeline called 'renderField'. In the second step of this, it's reading the fieldvalue:
Replace that one with your own custom class with something like this:
public void Process(RenderFieldArgs args)
{
Assert.ArgumentNotNull(args, "args");
if(args.RawParameters.Contains("Section"))
{
//Parse args.RawParameters
//Extract Section data
//Take args.Item.Template
//Resolve section
//Resolve fieldvalue
//Set this field value as args.Results.FirstPart
}
if (!string.IsNullOrEmpty(args.FieldValue))
{
args.Result.FirstPart = args.FieldValue;
}
else
{
args.Result.FirstPart = args.Item[args.FieldName];
}
}
Something in the line of:
args.Result.FirstPart = args.Item[args.Item.Template.GetSection("sectionName").GetField(args.FieldName).ID];
But now with error checks :)
Per official Sitecore Documentation, field names must me unique across sections.
This was also discussed here
精彩评论