-
Notifications
You must be signed in to change notification settings - Fork 1
Description
Feature Request: nav:collection equivalent in Blade/Antlers syntax
Problem
In the legacy Antlers syntax, there was a very useful nav:collection tag that allowed you to treat collection entries as navigation items with automatic navigation-specific properties like is_current, is_parent, and is_external.
Old syntax (worked great):
@foreach(Statamic::tag('nav:collection:'.$collection->handle)->fetch() as $item)
<a href="{{ $item['url'] }}" class="{{ $item['is_current'] ? 'active' : '' }}">
{{ $item['title'] }}
</a>
@endforeachIn the new Blade/Antlers syntax, there's no clear equivalent. You can use <s:collection> but it doesn't provide navigation-specific properties, or you can use <s:nav> but that requires creating a separate Navigation structure in the CP.
Current workaround (less elegant):
<s:collection from="my_collection" scope="entry">
<a href="{{ $entry->url }}" class="{{ $entry->uri === $current_uri ? 'active' : '' }}">
{{ $entry->title }}
</a>
</s:collection>Use Case
This is particularly useful when you want to:
- Display collection entries as navigation items
- Have automatic
is_currentdetection without manual URL comparison - Avoid creating redundant Navigation structures for simple collection-based menus
- Maintain DRY principles by not duplicating logic across multiple templates
Proposed Solution
Add a nav parameter or mode to the <s:collection> tag that enables navigation-specific properties:
<s:collection from="my_collection" nav="true" scope="entry">
<a href="{{ $entry->url }}" class="{{ $is_current ? 'active' : '' }}">
{{ $entry->title }}
</a>
</s:collection>Or alternatively, support <s:nav:collection> syntax similar to the old approach:
<s:nav:collection from="my_collection" scope="entry">
<a href="{{ $url }}" class="{{ $is_current ? 'active' : '' }}">
{{ $title }}
</a>
</s:nav:collection>Benefits
- Consistency: Brings back a beloved feature from legacy Antlers
- Simplicity: No need to create separate Navigation structures for simple collection-based menus
- DX improvement: Reduces boilerplate code for common navigation patterns
- Feature parity: Maintains feature parity between old and new syntax
Additional Context
The navigation-specific properties that were available in nav:collection and would be valuable in this context:
is_current- Whether the entry URL matches the current pageis_parent- Whether the entry is a parent of the current pageis_external- Whether the link is external- Proper handling of child entries for nested navigation
This feature would significantly improve the developer experience when working with collection-based navigation patterns.