Reputation: 23
I have a component and it has background image. I am able to render the image but I need the image to be editable in Experience editor but now the image is not editable.
<div style="background-image: url(@Model.Image.Src);">
<div>
<span>@Model.title</span>
<p>@Model.Description</p>
</div>
</div>
I tried to give <div style="background-image: url(@Editable(model => model.Image.src));">
But this did not work
Upvotes: 1
Views: 278
Reputation: 1443
There are a couple of options for making background images editable in Experience Editor:
<img>
tag when a page is loaded in Experience Editor mode and keep your current markup for other modes:@if (Sitecore.Context.PageMode.IsExperienceEditorEditing)
{
@Editable(model => model.Image)
}
else
{
<div style="background-image: url(@Model.Image.Src);">
...
</div>
}
Create a Custom Experience Editor button for your rendering:
/sitecore/content/Applications/WebEdit/Custom Experience Buttons
using the template Field Editor Button
Fields
with a pipe-separated list of field names that should be editable via this button ("Image" in your example)Experience Editor Buttons
After this you will start seeing a new button when selecting a rendering in Experience Editor:
The drawback of the second approach is that the new image will not be visible on the page immediately after making changes in the editing dialogue, so CMS users will have to save and refresh the page to see their changes.
Upvotes: 0