8

No, Glass Mapper can't map Template or TemplateItem out of the box. However, it's easy to create field mappers so that it can. Field Mappers To map Template, create the following field mapper: public class SitecoreFieldTemplateMapper : AbstractSitecoreFieldMapper { public SitecoreFieldTemplateMapper() : base(typeof(Template)) { } ...


6

This will work for the basic params; @using Sitecore.Resources.Media <div style="background-image:url(@HashingUtils.ProtectAssetUrl(string.Format("{0}?{1}", Model.Logo.Src, new MediaUrlOptions { MaxWidth = 200 })))">Hello</div>


4

It sounds like you are a victim of the change in the EnforceVersionPresence change that happened in Sitecore 8.1. Although, I'm not sure what version you upgraded from. The EnforceVersionPresence setting makes Sitecore return null item objects instead of a shell item object with zero versions. You have 2 options. Update your code to check that the item has ...


3

As per my knowledge there is no method to achieve your functionality in this way, only way is to use the inheritance by creating multiple class/interface. Since C# doesn't support multiple inheritance in class but you can achieve this using interface. I have never use multilevel inheritance for this but I guess that is also an option for this. An example of ...


3

This is not a glass mapper issue, but instead a miss on the full Enforce Language Presence implementation. Per Sitecore documentation: 1) Enable the enforceVersionPresence attribute This attribute is applicable to a <site> definition element. Patch it in appropriately. <site name="mysite"> <patch:attribute name="enforceVersionPresence"&...


3

The easiest way to solve this would be to use either a custom class or a dynamic one when you serialize: var folder = _sitecoreContext.GetItem<ISomeFolder>(dataSourceId) var list = folder.SubItems; var json = JsonConvert.SerializeObject(list.Select(subitem => new { ...


3

From what I understand, you want to do something like: @foreach (var person in Model.EventSpeakers) { <div class="speaker"> @Editable(person, p => p.Speaker_Image) </div> } You just pass the item as the first parameter to the @Editable


3

You want to change your ID property to type Guid. Also, you can add the attribute SitecoreId to the property. [SitecoreId] public Guid ID { get; set; } This should allow Glass to map to your class properly. You can see a really basic example of this on the Glass Mapper website: http://glass.lu/Mapper


3

Update your model to have the type of your TreelistEx field be an IEnumerable<Glass.Mapper.Sc.Fields.Image> instead of using IDs. Something like: using System.Collections.Generic; using Glass.Mapper.Sc.Fields; [SitecoreType(TemplateId = "{TEMPLATEID}")] public class ImageGroup { [SitecoreField(FieldId = "{FIELDID}")] public virtual ...


3

You can create a new child item template lets say ChildImage template which will contain the Image field. Parent template will have TreeListEx field which will allow to select child items (ChildImage). Parent Datasource ChildImage Class [SitecoreType(TemplateId=I_ImageListConstants.TemplateIdString )] public partial interface I_ImageList : IGlassBase { ...


2

In Glass Mapper v5, the determination for whether an item has versions has changed from using Sitecore.Data.Items.Item.Versions.Count to checking if Sitecore.Data.Items.Item[Sitecore.FieldIDs.Revision] is null or empty. It's possible that this new method of checking the existence of the __Revision field is potentially inaccurate in your solution and instance ...


2

Why not just have them in one list and just get the ones you want when you check the list? [SitecoreType] public class MyItemBaseType { [SitecoreField] public virtual string BaseProperty { get; set; } } [SitecoreType] public class MyItemType1 { [SitecoreField] public virtual string MyItemType1Property { get; set; } } [SitecoreType] public ...


2

In the upgraded version of Glass Mapper (5.3.15), I think by default it will perform mapping of all the models from IGlassBase interface during the application start. Looks like it is not performing the mapping on start up. Glass Mapper provides API to perform this mapping on demand that should convert the base glass model to corresponding template model. ...


2

Based on your last question and this question I am adding some details- In Glass mapper, two types of Models are being in use called - Template Models and Rendering Models - See more here - http://glass.lu/Blog/TemplateVsRendering It seems you are using Rendering Models, these are models that are designed to contain just the properties required by a ...


1

In order to use these new services, you have to first inject them with the Sitecore dependency injection container. Maybe that is the reason why you always get null results. There is a good blog post about it: https://www.coreysmith.co/glass-mapper-5-dependency-injection/ Also, I have written my simple solution if you are using Helix: https://...


1

I've experimented with this a bit, and the answer appears to be changing the type in SitecoreGlassMap to the concrete class. So continuing the example above, the mapping would be: public class TemplateMap : SitecoreGlassMap<Template> { public override void Configure() => Map(config => { config.Field(f => f.Field).FieldName("Field")...


1

Glass mapper is for mapping Sitecore items to Glass models. That's all it was designed to do. Don't try to shoehorn it into mapping things it wasn't designed for. Just use the Sitecore API and create a model. If you really must use a tool to do the mapping for you instead of just writing the code. Then have a look at AutoMapper, that is designed to map from ...


1

There is no such a thing like "correct order or items returned by Sitecore query". Only children of an item are sorted. Sort order information is stored on the parent item and if you use SitecoreChildren with Glass, you will get them in the order from Sitecore Content Tree, e.g.: [SitecoreChildren(IsLazy = false)] public virtual IEnumerable<Child> ...


1

Looking at your code, you're sending a state ID from your form in a POST action back to the server. Your model contains State property, but it's an object of State class. It's not possible to populate object from ID in a POST action automatically OOTB. What you should do instead is to change the type of State property in EmployeeModel class to Guid or ...


1

Still an issue unfortunately. I just needed the image URL so had to go down the route of implementing an extension method. Something like below public static string GetAbsoluteUrl(this Image value, ISitecoreContext sitecoreContext = null) { if (value == null || value.MediaId == Guid.Empty) { return string.Empty; } var mediaItem = (...


1

I think this issue may have been fixed in version 5.4.21 http://www.glass.lu/Mapper/Releases. There was an error in how Glass was caching view types which has been resolved. Can you update and see if this solves your issue. Commit: https://github.com/mikeedwards83/Glass.Mapper/commit/b4d5bb156110f990ac67f4e2a9a3274bbcf14137


1

You can use the attribute [SitecoreSelf] to continue mapping the current item on a nested object: public class Market { [SitecoreSelf] public virtual Text Name { get; set } } Then on the Text class you add the [SitecoreField] attribute to get the text field mapped. public class Text { [SitecoreField(FieldName = Templates.MarketItem.Fields....


1

You will need to tell it specifically to infer the type of the parent (also, the property should be marked virtual): [SitecoreParent(InferType = true)] public virtual C Parent { get; set; }


1

Not sure with your GlassMapper version, but anyway check SecurityDisabler, SitecoreType attribute (provide error details to get answer faster). Working solution with class (instead of interface) Model: [SitecoreType(TemplateId = "{[your template ID]}"] public class ChildItem { [SitecoreField("Image")] public virtual Image Image { get; set; } [...


1

It looks like you might have a global namespace declared in your Web.config Check your Web.config for the namespace Glass.Mapper.Sc. You shouldn't need to have a namespace for this in your root Web.config and these should be configured in the views folder.


Only top voted, non community-wiki answers of a minimum length are eligible