Developer forum

Forum » Ecommerce - Standard features » Include extension in imagepattern?

Include extension in imagepattern?

Anders Ebdrup
Anders Ebdrup
Reply

Hello,

 

We are trying to change our image pattern from: "/{SpImageFileName}.jpg" to just: "/{SpImageFileName}", so the image type doesn't matter and the file extension is instead included in the product custom field, but we cannot get it work.

 

Is that not supported?

 

Best regards, Anders

 


Replies

 
Scott Forsyth Dynamicweb Employee
Scott Forsyth
Reply

To add to your request, I just had the same topic come up today. Wildcard support would be very useful here. Our need is /{ProductNumber}-*.jpg. We would like alternative images to follow the pattern of {ProductNumber}-{anything}.jpg.

Regarding the extension, we've had that question asked a few times too, on whether it's possible to have a wildcard for the extension. I do know that could be difficult for the image handler to have an unlimited number of file types to consider, some /{SpImageFileName}.docx could be a problem for the image handler. But, if you trust your list of files, then it sure would be convenient to have wildcard support for the extension. 

One thing that you can do for the extensions now is to use the alternative images using the "Add New Row" option at the bottom. You could create a few patterns, like:

- /{SpImageFileName}.jpg
- /{SpImageFileName}.jpeg
- /{SpImageFileName}.png

 

 

 

 
Nicolai Pedersen
Reply

You can also seperate patterns in the same field with ;

"/{SpImageFileName}.jpg;/{SpImageFileName}.png"

We do not support wildcards in the new image pattern implementation because it requires an itereation over large collections many times on each pageload. It is slow. Without wildcards we can do it with dictionary lookups which does not give the same performance hit.

For small folders it is not a problem. But for large sites we have seen some issues with the wildcard.

BR Nicolai

 
Søren Ravn Lund
Reply

Could be awesome to have the documentation updated about wildcards in Imagepattern so one wouldn't spent time on getting it to work...

 
Nicolai Pedersen
Reply

Also you can create a class in code inheriting ImagePatternExtenderBase - it has 2 methods that can be overriden, ReplaceImagePath which is called before dynamicweb replace any tokens, and ReplaceFilePath which is called after dynamicweb has replaced its tokens.

So if you have a pattern like this: /{ProductID}_{SomethingYouMakeUp}.jpg you will get that pattern string in the ReplaceImagePath method call along with the product currently being rendered, and /prod1_{SomethingYouMakeUp}.jpg in the second call in ReplaceFilePath.

Then you can locate your own stuff and replace.

Just remember that these things are called MANY times on a page. If you show 30 products with 10 variants each and you have 3 image patterns it will be 10*30*3 = 900 times.

 
Nicolai Pedersen
Reply

@Søren

Yes. Will send it to doc team

 
Søren Ravn Lund
Reply

@Nicolai Thanks!

 
Nicolai Pedersen
Reply
This post has been marked as an answer

@Søren: Docs are updated.

Votes for this answer: 1
 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Oh wow... I did not know we could do "/{SpImageFileName}.jpg;/{SpImageFileName}.png"

Interesting as multiple customers has asked for this

 
Scott Forsyth Dynamicweb Employee
Scott Forsyth
Reply

Thanks Nicolai. Happy to see more info in the docs, and the extra considerations on the extra load for image-heavy pages, and also the code sample.

We've used a 'starts with' concept in the past, which is a pretty fast call in the operating system, but you're right that some sites would have enough files that even that could too much of a performance hit. 

 
Anders Ebdrup
Anders Ebdrup
Reply

Dear Nicolai,

 

We are once again struggling with have multiple patterns in the same field, as it seems like it only takes the last pattern into account.

So for this pattern: /{AN_ProductImages_Filename}.png;/{AN_ProductImages_Filename}.jpg only files matching /{AN_ProductImages_Filename}.jpg are found. But if we change the pattern to: /{AN_ProductImages_Filename}.jpg;/{AN_ProductImages_Filename}.png then only the png images are found.

 

Can you please try to look into this?

 

Best regards,

Anders

 
Anders Ebdrup
Anders Ebdrup
Reply

Dear Dynamicweb,

 

I have looked into the source code and have marked the issue with yellow below, as found images before the separator (;) are replaced by this line if nothing is found in the second iteration

                    List<string> foundImages = null;
                    bool isVariantImageFound = false;
                    foreach (TokenContainer tokenContainer in pattern.GetPatternTokens())
                    {
                        string imagePath = tokenContainer.PatternString;
                        imagePath = ReplaceTokensInImagePath(product, allSupportedPatternMappings, tokenContainer, imagePath);
                        foreach (var extender in extenders)
                            imagePath = extender.ReplaceImagePath(imagePath, product);
                        if (allFilePaths.TryGetValue(imagePath, out foundImages))
                        {
                            for (var i = 0; i < foundImages.Count; i++)
                            {
                                foreach (var extender in extenders)
                                    foundImages[i] = extender.ReplaceFilePath(imagePath, product);
                                if (!string.IsNullOrEmpty(foundImages[i]))
                                {
                                    foundImagePattern = tokenContainer.PatternString;
                                    if (foundImagePattern.Contains("VariantOption"))
                                    {
                                        isVariantImageFound = true;
                                    }

                                    break;
                                }
                            }
                        }
                    }

 

Can this be fixed in this week as we have a client going live Monday and are missing this feature??

 

Best regards,

Anders

 
Steffen Kruse Hansen Dynamicweb Employee
Steffen Kruse Hansen
Reply

Hi Anders,

I have just had QA looking into this problem, and they have been able to reproduce it.

We have created a bug for this in DevOps (#3130), and have sent it to a developer to fix it. So hopefully we have a fix ready tomorrow, and then we can talk about which options we have, so you can get the fix as soon as possible.

Best regards,

Steffen
 

 
Anders Ebdrup
Anders Ebdrup
Reply

Sounds really great, Steffen. Thank you

 
Steffen Kruse Hansen Dynamicweb Employee
Steffen Kruse Hansen
Reply
This post has been marked as an answer

In case anybody else needs this fix, it has been released in the latest Dynamicweb.Ecommerce package (1.10.73) which can be downloaded here:

https://www.nuget.org/packages/Dynamicweb.Ecommerce/1.10.73

Votes for this answer: 1

 

You must be logged in to post in the forum