I am creating a home page template, and I'd like to display the latest two articles there. Specifically, I'd like to show the first, and only first, image in the Bard field (named "body" as seen below) for the each article that appears.
I've got this:
{{ collection:articles paginate="false" as="articles" limit="2" }}
{{ articles scope="tag" }}
<div>
{{ title }}
{{ body }}
{{ if type == "image" }}
<img src="{{ glide :src='image' width='340' height='200' fit='crop' }}" />
{{ /if }}
{{ /body }}
</div>
{{ /articles }}
{{ /collection:articles }}
This dumps out all the images, but I can't figure out how to just get the first one. Is there a concept of "first" while looping through the fields? Or, preferably, a way of directly grabbing the first image (something like {{ body.image[0] }}?
This is what some example data looks like, so it seems that direct access rather than looping would be the way to go?
body:
-
type: text
text: '<h2>What is a yadda yadda'
-
type: image
image: /assets/img/dispositions.png
alignment: center
size: Oversized
caption: 'Download the dispositions sheet for more options.'
-
type: text
text: '<h2>What kinds of yadda yadda'
-
type: image
image: /assets/img/dispositions-1527203093.png
caption: 'Define rules to assign buckets, dispositions, and assignments for content'
size: Oversized
alignment: center
-
type: text
text: '<h2>What are some example yadda yadda'
id: afbbaa34-3ff3-45b8-a7a7-56b2c5f471d3
Thanks.