Developer forum

Forum » Swift » Missing image logic

Missing image logic

Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi guys,

I am trying to make the setup a bit more consistent in terms of using the missing image from settings.
In default Swift templates (Swiftv2-ProductMedia.cshtml) I have found a hardcoded value for missing image: /Files/Images/nopic.png

I would like to change that and always use the Missing image set on Products and/or Groups in the Image settings:

How can I get that value?

Also, in DW9 we use to have an altImage property for GetImage. Is that still an option in DW10?
I see that we now have an option to send 404 for missing images and apparently it is supposed to send the alternative image, but I could not make it work.

Thank you,

Adrian

 


Replies

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Hi Adrian

There are 2 things to consider - missing image on a product - and a file send to getimage that does not exist. They are not the same.

Here’s the key difference:

Product “missing image”

  • This happens when the product simply has no image assigned (e.g. image path is empty).

  • In that case the template typically ends up generating a GetImage URL where image= is empty or no getimage call at all - depending on your solution.

  • That’s not a “missing file” scenario — it’s “no source was provided”, because the product data contains no image value.

GetImage/ImageHandler “missing image”

  • This happens when the request does contain an Image parameter, but the file it points to does not exist on disk.

  • In ImageHandlerMiddleware, the flow is:

    1. Read Image and map it to a physical path

    2. If the file exists → use it

    3. If the file does not exist → then (and only then) read AlternativeImage and use that instead

So: AlternativeImage is not a “product has no image” fallback.
It is a “the provided Image path is broken / file missing” fallback.

In other words:

  • Empty Image (product has no image) → the template must handle it (choose a placeholder, don’t output GetImage, etc.)

  • Non-empty Image, but file missing → ImageHandler can fall back to AlternativeImage (or 404 depending on settings)

 

You can read the information from settings: "/Globalsettings/Ecom/Picture/NoPicture/Large"

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Nicolai,
Thank you for the detailed description.

I agree with the separation between no image and invalid image.
However, shouldn't Swift handle the missing image logic in the templates? And instead of using a hardcoded value (/Files/Images/nopic.png), read it from the settings? I assume AlternativeImage it is read from the config, right?
I have managed to eventually find the information about the default missing image, but in GlobalSettings.Ecom.config. I initially searched for it in the general config.

Thank you,

Adrian
 

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

AlternativeImage is not read from config - it is parameter only. We do not use it - and neither should we. In Swift 2 we use TryGetImage - which will return false if the image does not exist. AlternativeImage parameter is old world and only for bad data in a bad implementation.

The fallback in Swift templates is only used if configuration is not returning a missing image from config.

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Nicolai,

I understand. All I am saying is that Swift is using a hardcoded value in the template instead of reading it from a configuration. And this does not sound like a good idea as long as there is a configuration to use.
Don't you think?

Thank you,
Adrian

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

No, Swift (Dynamicweb) uses the configured no image setting if specified - and Swift then falls back if the configuration also do not return anything. 

The viewmodels will contain the no image from configuration if present. 

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Well,
I have found 6 results in 3 files in the standard Swift distribution:

Adrian

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Hi Adrian

You do not understand what I write :-). I know they are there - and they should be there...

It works like this:

  • "Product image"
  • "Missing image" setting (If product image is not set, this is used)
  • Fallback image in template (If "missing image" is not set and the "Product image" is also not set, the fallback in the template is used.
     
 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

I am sorry, now I get it :)

I apologize 🙏

Adrian

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

No problem ;-)

 

You must be logged in to post in the forum