New: Learn Statamic on Laracasts!

We've retired the forum in favor of GitHub Discussions.

New conversations can be started on GitHub. Existing conversations will remain for a while longer.

Head over to GitHub →

Limit array to just get the first key and value?

Frederic Bouin April 4, 2021 by Frederic Bouin

How do I limit a dynamic array to just get the first key and value?

to loop through all of them I would do

{{ foreach:array }}
  {{ key }} {{ value }}
{{ /foreach:array }}

but adding the limit:1 modifier doesn't work, or I don't know how to add it. I'm assuming because foreach iterates through all the key values, so its counter productive to try and add a limit modifier.

{{ foreach:array limit="1" }}
  {{ key }} {{ value }}
{{ /foreach:array }}

What would be the proper approach here?

Answered by Jason Varga!
>>>>>>> Answered <<<<<<<
6 Replies
4 Followers