Skip to content Skip to footer navigation

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

Without scoping, {{ title }} inside the loop falls back to the page's title. Prefix the variables with a scope to get exactly what you want.

{{ 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.