富文本字段编辑器中图像 src 属性中的 Sitecore 参考媒体库图像
Sitecore Reference media library image in an image's src attribute inside Rich Text field editor
我正在使用 sitecore 8.1,我有一个模板包含 "Rich Text" 类型的字段,我正在基于此模板创建项目并在该字段中存储 HTML 内容。所有 HTML 标签和一切正常,除了 HTML 内容中包含的图像(在 src 属性中),我已经尝试了以下所有方案但都失败了:
Note: All the following scenarios' results are showing the image properly inside the Rich Text Editor inside sitecore CMS but when trying to render the HTML in a mobile web view or any browser, the HTML looks properly but just images are empty.
And there is only one way I've tried and it worked but doesn't
meet my requirements which is by mention an external URL inside src like:
src="http://i.telegraph.co.uk/multimedia/archive/03589/Wellcome_Image_Awa_3589699k.jpg"
场景:
- 上传媒体库中的图片并使用Image Map Editor(从富文本编辑器调用)引用上传的图片,因此图片的src属性包含类似
src="-/media/5EA5C007FFFF4688A0B7E6F58B79D2E8.ashx?h=183&w=250"
的值
在这里我也尝试将扩展名从 ashx 更改为原始扩展名并删除后缀参数但没有结果。
- 在 src 属性中明确指定媒体库中的图像 url,例如
src="/-/media/Contents/Images/foobar"
而且在这里我尝试更改添加原始扩展名但没有结果。
- 使用 this solution 但它损坏了我所有的媒体文件,而且在我上传新文件后,仍然无法在 HTML 网络视图或浏览器中看到图像。
- 在 sitecore 网站目录中添加原始图像,如
\website\contents\images
并通过 HTML 像任何普通图像引用一样引用它
src="/contents/images/foobar.jpg"
喜欢 src="~/contents/images/foobar.jpg"
但没有任何结果或改变。
我更愿意使用 Sitecore 的媒体库来避免最后一种情况
不使用ashx扩展名,可以直接在富文本中使用图片的sitecore路径,如下图:
src="~/media/path/to/image/logo.jpg"
然后按照您上面提供的,从富文本中检索值,如下所示:
var richTextValue = item.Fields["Body"].Value;
谢谢
我正在使用 sitecore 8.1,我有一个模板包含 "Rich Text" 类型的字段,我正在基于此模板创建项目并在该字段中存储 HTML 内容。所有 HTML 标签和一切正常,除了 HTML 内容中包含的图像(在 src 属性中),我已经尝试了以下所有方案但都失败了:
Note: All the following scenarios' results are showing the image properly inside the Rich Text Editor inside sitecore CMS but when trying to render the HTML in a mobile web view or any browser, the HTML looks properly but just images are empty. And there is only one way I've tried and it worked but doesn't meet my requirements which is by mention an external URL inside src like:
src="http://i.telegraph.co.uk/multimedia/archive/03589/Wellcome_Image_Awa_3589699k.jpg"
场景:
- 上传媒体库中的图片并使用Image Map Editor(从富文本编辑器调用)引用上传的图片,因此图片的src属性包含类似
src="-/media/5EA5C007FFFF4688A0B7E6F58B79D2E8.ashx?h=183&w=250"
的值 在这里我也尝试将扩展名从 ashx 更改为原始扩展名并删除后缀参数但没有结果。 - 在 src 属性中明确指定媒体库中的图像 url,例如
src="/-/media/Contents/Images/foobar"
而且在这里我尝试更改添加原始扩展名但没有结果。 - 使用 this solution 但它损坏了我所有的媒体文件,而且在我上传新文件后,仍然无法在 HTML 网络视图或浏览器中看到图像。
- 在 sitecore 网站目录中添加原始图像,如
\website\contents\images
并通过 HTML 像任何普通图像引用一样引用它src="/contents/images/foobar.jpg"
喜欢src="~/contents/images/foobar.jpg"
但没有任何结果或改变。
我更愿意使用 Sitecore 的媒体库来避免最后一种情况
不使用ashx扩展名,可以直接在富文本中使用图片的sitecore路径,如下图:
src="~/media/path/to/image/logo.jpg"
然后按照您上面提供的,从富文本中检索值,如下所示:
var richTextValue = item.Fields["Body"].Value;
谢谢