Creating featured image for pages (using capture), but need to check if image is available

Mike_Lythcott
Excursionist
14 1 1

Hi, I am creating the ability to add a featured image to pages, and I have one issue.
I am using this code to upload an image in the dashboard, titled the same as the handle and reference it on page. Works great!

{% capture pageimage %}page-{{ page.handle }}.jpg{% endcapture %}
<img src="{{pageimage| file_img_url: 'medium' }}"/> 

BUT, if a page doesn't have an image uploaded, it still captures the path to the image, but that path is a 404 obviously.

SO for those pages without an image uploaded, how would I say:

"if image is captured, display it, else if captured image path is a 404, display something custom"

0 Likes