I am creating Sharepoint page layouts using a text editor (company won't allow me to install Sharepoint Designer). In one of my layouts, users can add an image using a RichImageField. My layout code looks like this:

<PublishingWebControls:RichImageField FieldName="PublishingPageImage" runat="server"/>

I would like this field to alter the background-image CSS property of a <div> rather than simply render as a standard HTML <img> tag. I know I can easily accomplish this with JavaScript, but I was wondering if there was a way of doing this at the page-layout template level?

In my ideal world it would be something like this:

<div id="hero" style="background-image:url('${RichImageField.src}')">My Hero Area</div>

So, to reiterate: Is it possible to render a RichImageField as a div's CSS background image (without JavaScript)?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.