Sitecore Glass Mapper(v4):通过RenderImage添加自定义查询字符串参数 [英] Sitecore Glass Mapper (v4): Add custom query string parameter via RenderImage
问题描述
使用Glass Mapper for Sitecore版本4(MVC),我需要以下方法调用:
Using Glass Mapper for Sitecore version 4 (MVC), I need the following method call:
@Html.Glass().RenderImage(Model, x => x.PhotoField, new {cropregion = xmlValue.GetCropRegion()}, true, true)
导致:
<img src="/sitecore/shell/-/media/Default-Website/cover.jpg?h=550&w=1600&la=en&hash=2986CA8291803D4A8EAC3B5A1C276E27D4877DCC&cropregion=534,11,1348,548" width="1600" height="550" />
当前,RenderImage调用将导致将cropimage
作为属性而不是图像的查询字符串添加.似乎有一个值列表,如果在RenderImage中传递,则将作为查询字符串参数而不是属性添加,并且该列表似乎是在主Config
类中定义的:
Currently, the RenderImage call will result in the cropimage
being added as an attribute rather than on the query string of the image. There seems to be a list of values that, if passed in RenderImage, will be added as query string parameters rather than attributes, and this list seems to be defined in the main Config
class:
ImageQueryString = new HashSet<string>(new[]
{
ImageParameterKeys.OUTPUT_METHOD,
ImageParameterKeys.ALLOW_STRETCH,
ImageParameterKeys.IGNORE_ASPECT_RATIO,
ImageParameterKeys.SCALE,
ImageParameterKeys.MAX_WIDTH,
ImageParameterKeys.MAX_HEIGHT,
ImageParameterKeys.THUMBNAIL,
ImageParameterKeys.BACKGROUND_COLOR,
ImageParameterKeys.DATABASE,
ImageParameterKeys.LANGUAGE,
ImageParameterKeys.VERSION,
ImageParameterKeys.DISABLE_MEDIA_CACHE,
ImageParameterKeys.WIDTH,
ImageParameterKeys.HEIGHT
});
所以,我的问题是:对这个图像参数键哈希集添加"cropregion"的最佳方法是什么?我是否应该编写自己的配置文件并将其替换为现有的Glass Mapper配置类?还是在初始化Glass时有某种方法可以将另一个值插入此HashSet中?
So, my question is: what's the best way for me to add "cropregion" to this image parameter key hashset? Should I write my own Config file and substitute it for the stock Glass Mapper config class? Or is there some way for me to insert another value into this HashSet when Glass is initialized?
推荐答案
我认为您应该可以在GlassMapperScCustom.CreateResolver
方法中添加一行.试试这个:
I think you should be able to just add a single line to your GlassMapperScCustom.CreateResolver
method. Try this:
public static IDependencyResolver CreateResolver(){
var config = new Glass.Mapper.Sc.Config();
config.ImageQueryString.Add("cropregion");
var dependencyResolver = new DependencyResolver(config);
// add any changes to the standard resolver here
return dependencyResolver;
}
这篇关于Sitecore Glass Mapper(v4):通过RenderImage添加自定义查询字符串参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!