Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top