Sitecore-参数模板中的Image字段 [英] Sitecore - Image field in parameter template
本文介绍了Sitecore-参数模板中的Image字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我在参数模板中有一个图像字段,在c#中获取图像的URL涉及哪些步骤?
推荐答案
@mresser就应该和不应该作为呈现参数提出了有效的观点。但是,我不认为Sitecore故意使在参数模板中使用图像字段变得困难。他们只是在现有的键-值对呈现参数功能的基础上构建了参数模板功能。
如果渲染参数模板上的图像字段的名称为BackgroundImage
,则可以使用以下代码获取所选图像的URL:
var imageId = XmlUtil.GetAttribute("mediaid", XmlUtil.LoadXml(this.Parameters["BackgroundImage"]));
MediaItem imageItem = Sitecore.Context.Database.GetItem(imageId);
backgroundImageUrl = MediaManager.GetMediaUrl(imageItem);
如果您的子布局还没有提供Parameters属性的基类,则还需要添加以下内容:
private NameValueCollection parameters;
public virtual NameValueCollection Parameters
{
get
{
if (this.parameters == null)
{
var parameters = this.Attributes["sc_parameters"];
this.parameters = string.IsNullOrEmpty(parameters)
? new NameValueCollection()
: WebUtil.ParseUrlParameters(parameters);
}
return this.parameters;
}
}
这篇关于Sitecore-参数模板中的Image字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文