How can I get Sitecore Field Renderer to use a css class for an image

試著忘記壹切 提交于 2020-01-02 17:54:28

问题


Using Sitecore (7) & MVC, I'd like to know how to add a css class attribute for an image to the field renderer in sitecore.

Without Sitecore it looks like this:

<div class="background-container">
   <img src="/images/background-1.jpg" class="background">
</div>

With Sitecore:

<div class="background-container">
   @Html.Sitecore().Field(Constants.Fields.HomeBackgroundImage)
</div>

There doesn't seem to be a way to add the class background to the image itself in Sitecore. Is there another way to do this?

Thanks.


回答1:


This was what I was looking for:

@Html.Sitecore().Field("MyFieldName", myItem, new { Parameters = new SafeDictionary<string> { { "enclosing-tag", "h2" } } })

See Extending the Sitecore RenderField pipeline.



来源:https://stackoverflow.com/questions/22233831/how-can-i-get-sitecore-field-renderer-to-use-a-css-class-for-an-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!