Forum

Thread tagged as: Question

If statement image type?

Is it possible to use a images mime type inside a perch:if statement?

Damon Golding

Damon Golding 1 points

  • 6 years ago

One way you could do this is to test the mime type then pass a variable into template if statement, that is unless Drew has a simpler way to do this... Cause he's pretty awesome... :)

Drew McLellan

Drew McLellan 2638 points
Perch Support

You can't, but that's an interesting idea. I'll see what I can do.

I found a bug with srcset in chrome where if the path/image for 1x and 2x are they same chrome displays the image but at 50%. Example here.

So my plan was to see if the paths are the same - then don't output srcset. This is mainly for SVGs.

Drew McLellan

Drew McLellan 2638 points
Perch Support

You can compare paths but not mime types.

Unfortunately I can't compare paths as I'm using the density attribute to create the images, unless there is a way to access the density paths in a if statment?

Drew McLellan

Drew McLellan 2638 points
Perch Support

If the images are different densities they'll have different paths - if they're the same density the same file should be reused.

The problem is with SVGs. As perch doesn't modify them the same path is outputted for both density paths.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ah, of course. So if it's always the same file, does it matter which is used?

It doesnt matter which file is used no, the issue is with srcset bug in chrome as it displays the SVG as 50%.

For now I have set the width (along with max-width:100%) using output="w" which does the trick. I was just looking for a 'nicer' way of doing it.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ah ok.