Sep 24, 2020 2 min read

Laravel’s Array Get for Statamic

I use this addon in every Statamic project

  • Build
Curtis Blackwell

Curtis Blackwell
Manager, Digital Product Delivery

Margaret Thatcher, Ronald McDonald, David Bowie, Zendaya, Vanessa down the street. What do these people (does Ronnie count as a person?) have in common? Hell if I know.

I wrote a Statamic 3 addon that I’ve been copying and pasting into every Statamic project I work on. It’s basically Laravel’s Arr::get() helper in Antlers. I used something similar in v2 back when Jim-Jam and I cranked out Statamic builds left and right and I more actively battled my nemesis.

Left: Jim-Jamm, wearing a hat and looking off into the distance.  Right: My nemesis, with a devilish grin and horns scribbled on

It helps me:

  • Streamline my markup

  • Easily add new variants (especially easy for minor differences like colors, sizes, padding… all that jazz 🎷) (doubly-especially wonderful with Tailwind)

  • Allow content authors to oh-so-simply choose which variant to render

  • And probably some other stuff not coming to mind right now 🤔

Anyway, check it out on GitHubPackagist, and the Statamic Marketplace. Let me know if you come up with more interesting use cases or if you run into any problems!

Array Get addon code with Highland's logo in the lower right corner.

Addon in the Statamic MarketplaceOh, yes. One other neat thing I didn’t document because it’s more of a side effect than an intentional feature: Array Get allows you to throw Antlers code in your front-matter and have it parsed in the output. I did that all the time in v2 (and probably v1?), but (last time I checked) v3 doesn’t support Antlers in your front-matter.