views:

253

answers:

2

Hi,

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

+3  A: 

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 :)

Alex de Groot
In our project we are already overloading the sitecore usercontrols so adding this code will be a walk in the park. Thank you Alex.
Zooking
A: 

Per official Sitecore Documentation, field names must me unique across sections.

This was also discussed here

Mark Cassidy