7

I have a multi-language website running Sitecore 8.1 and using Glass Mapper 4.2.1. The content is translated in all needed languages, but the configuration item exist only in English.

When I now have the Sitecore.Context.Language to German and load a configuration item, Glass Mapper is loading this in English. That's ok and wished, as this item is not existing in German. Within this configuration item I have a property to a referenced item that exists in English, German and French. Unfortunately Glass Mapper now loads this item in English, as the configuration item is loaded in English instead of using the Sitecore.Context.Language. Is there a possibility to load the referenced item directly in the Sitecore.Context.Language?

Best regards, Thomas

  • can you please provide the glass model class that you are using? – Andrey Bobrov Jan 19 '17 at 15:50
  • It's a Sitecore reference field for that Glass Mapper uses the SitecoreFieldTypeMapper (see github.com/mikeedwards83/Glass.Mapper/blob/master/Source/…). The problem for me is on line 57 I believe. There it uses the item.language instead of the Sitecore.Context.Language. – wene37 Jan 22 '17 at 17:47
2

To me this makes sense as a default behavior for Glass (as seen here)... if an item is loaded in a language, traversing other content off that item should be in the same language.

This is why Glass Maps and delegates are great, imho, because you can easily override these behaviors or otherwise introduce your own mapping logic. For example, assuming that Config is your configuration (in English) and ConfigReference is the type you want to retrieve from the Config Reference field (in the context language):

public class ConfigGlassMap : SitecoreGlassMap<Config> { public override void Configure() { Map(config => { config.Delegate(x => x.ConfigReference).GetValue(context => context.Service.GetItem<ConfigReference>(Guid.Parse(context.Item["Config Reference"]), Sitecore.Context.Language)); }); } }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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