Query to select image from field with different blocks

There is a field for a “cover” for a project. in this field I can select between an image block or a local video block with a poster image. in the panel, under “projects” I want to show either that image or that poster image in the card for the project based on which block was used for the cover field.

this works as stand alone queries
query: page.cover.toBlocks().first.vidposter.toFile()
query: page.cover.toBlocks().first.image.toFile()

I look for something like:
query: page.cover.toBlocks().first.image.toFile() or page.cover.toBlocks().first.vidposter.toFile()

what would be the correct query for that?
Thank you for your wisdom.

Your best bet is to move this logic to a custom page method, where you can check what is set and return accordingly.

1 Like

This solves the issue:

query: page.cover.toBlocks().first.image.toFile() ?? page.cover.toBlocks().first.vidposter.toFile()

Which ChatGPT actually solved :slight_smile: that stuffs getting scary

1 Like

Ah, right, I keep forgetting that query language got so much more powerful. I’m no longer needed, it seems. AI rules.

1 Like

@texnixe nah… your the best :slight_smile:

1 Like