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)
}
15
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 ...
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/...
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/...
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. ...
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>(...
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 ...
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 '...
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&...
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....
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 ...
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 ...
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:
...
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 ...
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 ...
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 ...
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 ...
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 ...
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'...
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, ...
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")] ...
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 ...
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(...
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....
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 ...
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 { ...
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 ...
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 ...
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
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
glass-mapper × 252experience-editor × 25
upgrade × 14
mvc × 12
sitecore-api × 8
caching × 8
sitecore-client × 7
tds × 7
links × 6
sxa × 5
presentation × 5
performance-optimization × 5
dependency-injection × 5
language-fallback × 5
content-search × 4
multilingual × 4
media-library × 3
security × 3
helix × 3
datasource × 3
unit-testing × 3
renderfield × 3
razor × 3
configuration × 2
templates × 2