2

I am creating a script to fetch rendering parameters of a sublayout and edit data template item field data based on the values of fields of rendering parameters.

I was able to fetch renderings in .aspx page using the code Sitecore.Layouts.RenderingReference[] renderings = ProfileItemWithLanguage.Visualization.GetRenderings(Sitecore.Context.Device, true);

But this is always giving me shared renderings. I have different data in different languages and need to fetch language specific data.

Please advice.

1 Answer 1

4

You can try something like this one:

var sharedRenderings = GetRenderings(Sitecore.Context.Item, Sitecore.FieldIDs.LayoutField);
var finalRenderings = GetRenderings(Sitecore.Context.Item, Sitecore.FieldIDs.FinalLayoutField);


private static int GetRenderings(Sitecore.Data.Items.Item item, Sitecore.Data.ID renderingFieldId)
{
    var field = item.Fields[renderingFieldId];
    var layoutXml = Sitecore.Data.Fields.LayoutField.GetFieldValue(field);
    var layout = Sitecore.Layouts.LayoutDefinition.Parse(layoutXml);
    var deviceLayout = layout.Devices[0] as Sitecore.Layouts.DeviceDefinition;
    return deviceLayout != null ? deviceLayout.Renderings : null;
}

I used code from this answer: https://sitecore.stackexchange.com/a/4956/277

1
  • This worked for me. I got what the issue was. I had set default values in rendering parameters using standard values. Apparently, if you have not manually updated the rendering parameters, then __Rendering and __FinalRendering fields remain empty (Even when they show default values). This was making the rendering fields data to not show up in the script.
    – Shaurya
    Dec 2, 2018 at 14:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.