Developer forum

Forum » Rapido » Overlay rendering no image as background image

Overlay rendering no image as background image

Mafalda Correa
Mafalda Correa
Reply

Hi,

I noticed there's a small bug in the Overlay.cshtml code, which is forcing a placeholder image as background image when the user doesn't choose any image.

In the code, the imagePath variable is defined as:

string imagePath = Model.Item.GetFile("Image") != null ? Model.Item.GetFile("Image").PathUrlEncoded : "";

This means that if there's no image, imagePath will be an empty string. Then it goes on to define imagePosition if imagePath is not null or empty. But since imagePath is empty, it doesn't define imagePosition, leaving it as empty, which further down in the code, defaults to the else black in the imagePosition if condition, which renders the content passing the imagePath:

@RenderContent(contentColumnClass, textAlignment, buttonAlignment, imagePath)

The problem is, we're passing the imagePath as an empty string, but inside the helper to determine whether we need to render background image or not, we're validating if the parameter (backgroundImage) is different than null.

@if (backgroundImage != null) {
    <div class="background-image dw-mod">
        <div class="background-image__wrapper dw-mod">
            @Render(new Image { Path = backgroundImage, CssClass = "background-image__cover", ImageDefault = new ImageSettings { Width = 1000, Height = 1000 }, FilterPrimary = ImageFilter.Darken })
        </div>
    </div>
}

But imagePath is empty, not null, so the it validates as true and the background image is rendered with an empty string as path.

See the repro here: https://www.screencast.com/t/4VJTrbHrP7

I've already fixed it simply by doing @if (!string.IsNullOrEmpty(backgroundImage)) instead of backgroundImage != null.


Replies

 
Olga Shedko Dynamicweb Employee
Olga Shedko
Reply

Hello Mafalda,

Thank you very much for this finding, new tfs #89232 has been created for fixing this issue.

Best regards,

Olga | QA

 

You must be logged in to post in the forum