Scope Modifier
Adds a named scope prefix to each item in an array or collection, letting you access variables with that prefix to avoid collisions with the parent context.
This is the modifier equivalent of the scope parameter on the Collection tag, but usable on any array β like the results of a taxonomy tag, a Replicator field, or any custom array of entries.
title: My Favorite Posts
posts:
- title: Bear Hibernation Tips
slug: bear-hibernation
- title: Cactus Cuddles
slug: cactus-cuddles
Inside the loop, {{ title }} uses the item's title when present, and can fall back to the page's title when it is missing. A scope makes it explicit that you want the item's value.
{{ posts | scope('post') }}
<a href="/{{ post:slug }}">{{ post:title }}</a>
{{ /posts }}
@foreach (Statamic::modify($posts)->scope('post')->fetch() as $item)
<a href="/{{ $item['post']['slug'] }}">{{ $item['post']['title'] }}</a>
@endforeach
<a href="/bear-hibernation">Bear Hibernation Tips</a>
<a href="/cactus-cuddles">Cactus Cuddles</a>
The original (unprefixed) variables are still available inside the loop β the scope is added alongside them, not as a replacement.