26 votes
Accepted

Editable Sitecore fields with Glass

This should give you what you want: @using (Html.Glass().BeginRenderLink(Model, m => m.MyLinkField, null, true) { @Html.Glass().RenderImage(Model, m => m.MyImageField, null, true) }
user avatar
  • 2,618
14 votes
Accepted

What are the options for Glass Mapper model attributes?

SitecoreChildrenAttribute - Maps children of the current item. Expects an IEnumerable<T> SitecoreFieldAttribute - Maps from a field on the current item SitecoreFieldFieldValueAttribute - Used to ...
user avatar
  • 3,263
13 votes
Accepted

Can GlassMapper caching be disabled at a site level?

Yes, use the glassCache attribute. A value of anything other than false means the cache will be enabled for that site: https://github.com/mikeedwards83/Glass.Mapper/blob/master/Source/Glass.Mapper.Sc/...
user avatar
12 votes
Accepted

GlassMapper Parent Item

You can use the [SitecoreParent] attribute for that: [SitecoreParent] public virtual BasePage Parent { get; set; } It is also mentioned in the Tutorial 17 (http://www.glass.lu/mapper/sc/tutorials/...
user avatar
12 votes
Accepted

Glass BeginRenderLink not showing text node

The fact that BeginRenderLink does not render link text inside the <a> tag is not bug. As Glass Mapper documentation says, BeginRenderLink is not really for displaying the default link text. ...
user avatar
11 votes
Accepted

How to convert a Sitecore Item object into a strongly-typed Glass model?

Instantiate a SitecoreContext and call the Cast<T>() method. ISitecoreContext context = SitecoreContext.GetFromHttpContext(); var myTemplateObject = context.Cast<MySite.Model.MyTemplate>(...
user avatar
  • 1,693
10 votes
Accepted

Item not found when saving page in Experience Editor

So it's took me all of yesterday and most of today to figure this out. In the end it was nothing to do with my code or configuration at all. The log files showing some errors were a Red-Herring and ...
user avatar
10 votes
Accepted

Html.Glass helper not found after installing Glass Mapper v4

The problem was with MVC setup in the project not with Glass. This was the solution - http://samirvaidya.blogspot.hu/2015/10/the-type-expression-is-defined-in.html. The error was exactly The type '...
user avatar
10 votes

After upgrading to Glass Mapper 5, unable to globally enable lazy loading

In version 5 config.EnableLazyLoadingForCachableModels setting was removed and "IsLazy"-setting was removed from all model property configuration, like [SitecoreChildren(IsLazy = false)] IEnumerable&...
user avatar
  • 3,021
9 votes
Accepted

Glass SitecoreContentContext has Database property null

Is you want to use the database represented by Sitecore.Context.Database then you should use SitecoreContext. The service SitecoreContentContext is a wrapper for the database Sitecore.Context....
user avatar
9 votes
Accepted

Sitecore Habitat with Glass Mapper

You can put it to the Foundation layer. Any project in any layer can have references to the Foundation layer. Also, a Foundation project can have references to another Foundation project, but you need ...
user avatar
  • 1,410
9 votes
Accepted

How to map a datasource in DropList to a specific parameter on selection?

The DropList field only stores the name of the item selected. To accomplish what you are trying to do, you need to use a Droplink field instead. The Droplink field will store the ID of the selected ...
user avatar
  • 409
9 votes
Accepted

How do I map a list of Templates with Glass Mapper?

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: ...
user avatar
  • 2,618
8 votes
Accepted

Glass Models not populating

You can't mix configuration methods in Glass Mapper. Your IPage model is using attribute configuration but your IGlassBase model is using fluent configuration. Remove the SitecoreField attributes from ...
user avatar
  • 2,618
8 votes

Attempt by method 'Glass.Mapper.Sc.Utilities.get_IsPageEditor()' to access method 'Sitecore.Context+PageMode.get_IsPageEditor()' failed

You need to use latest version of glass mapper: https://www.nuget.org/packages/Glass.Mapper.Sc/4.2.1.188 with Sitecore 8.2 In the new version you have: namespace Glass.Mapper.Sc { public class ...
user avatar
  • 17.8k
8 votes

How to convert a Sitecore Item object into a strongly-typed Glass model?

Looks like SitecoreContext.GetFromHttpContext() is obsolete. The recommend way is SitecoreContextFactory.Default.GetSitecoreContext() My preferred way is new SitecoreContext() So casting can be ...
user avatar
8 votes
Accepted

How can I add custom attribute values to my Glass models generated by TDS?

You can update the GlassV3Item.tt file and make use of the Custom Data property in TDS to set whether a field should not be lazy loaded. Let's add some comments to keep this clean. Add this near the ...
user avatar
  • 13.7k
8 votes
Accepted

Weird URL mapping for /hu and /se

This is Sitecore's default language mapping. It recognizes hu as Hungarian and se as Swedish. Happens in the StripLanguage processor in the <preprocessRequest> pipeline. If you never need ...
user avatar
  • 24.4k
8 votes
Accepted

Glass Mapper language caching

If Cachable attribute equals true, it means that Glass Mapper will apply cache for this object. I've decompiled the Glass.Mapper.Sc.dll, where CacheKeyGenerator is defined and we can see that it doesn'...
user avatar
8 votes
Accepted

SitecoreContext throwing error after Sitecore upgrade

As I can see you are using GlassMapper 5 version and in GlassMapper 5 version SitecoreContext, GlassView, GlassController are obsolete. On behalf of SitecoreContext you can Use either IRequestContext, ...
user avatar
7 votes
Accepted

Glassmapper fields displaying null despite correct item ID

The problem could be that you use AutoMapping. If the field names are not exactly the same as the property names then Glass can't solve these. I would try to use [SitecoreField("First Text Line")] ...
user avatar
7 votes
Accepted

Glass Mapper Model too deep. Potential lazy loading loop exception after upgrading to version 4.3.4.196

Please see the release notes for 4.3 which explain how to remove the depth check: http://www.glass.lu/Blog/Release4-3 The depth check is designed to capture models where lazy loading is disabled but ...
user avatar
7 votes
Accepted

A ton of Glass.Mapper INFO messages in logs

I guess is a mistake in code. From my point of view these lines must be on Debug mode not Info mode. On line 124 we have Sitecore.Diagnostics.Log.Info("GetModelFromView {0} {1}".Formatted(...
user avatar
  • 17.8k
7 votes
Accepted

How can I make responsive images editable?

There are a couple good ways to do this Provide a different interface when the page is in edit mode. Image with retina/non-retina support using Glass: @if (Sitecore.Context.PageMode....
user avatar
7 votes

How to register Glass Mapper ISitecoreService in my Ioc

I wanted to add this as the other answers are close, but not 100% IMO. First - SitecoreContext and SitecoreService have overloaded constructors. So you have to use a factory registration to be able ...
user avatar
  • 19k
7 votes
Accepted

Getting full image URL using Glass Mapper without RenderImage

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 { ...
user avatar
  • 213
6 votes
Accepted

Using Unicorn to Generate Glass Mapper Models

The Sitecore.CodeGenerator project can convert serialized Sitecore items into GlassMapper classes, and it contains support for the Rainbow serialization format (used by Unicorn 3). The project page ...
user avatar
  • 4,134
6 votes

Glass Mapper Item Creation issue

I was able to figure this one out, with the help of Tamás Tárnok above. The solution was to add [SitecoreType(TemplateId = "Your_Sitecore_Template_Id")] to the implemented class. More information is ...
user avatar
6 votes

Html.Glass helper not found after installing Glass Mapper v4

I added @using Glass.Mapper.Sc.Web.Mvc on Top and it solved my problem
user avatar
  • 161
6 votes
Accepted

How do I render custom attributes on a General Link using the latest version of Glass Mapper

Before implementing this solution you will need to download the latest nightly. I made a couple of changes to make it easier to solve this problem. Ok, firstly create a sub-type to map the additional ...
user avatar

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