Skip to content

$index not available in Blade Collection / Taxonomy tag #11377

Closed
@stuartcusackie

Description

@stuartcusackie

Bug description

The documentation for both the collection tag and the taxonomy tag show a list of variables, including $index.

I cannot figure out how to access these variables in Blade. I've dump all_defined_vars but I don't see it there. Seems like a bug.

How to reproduce

Try to access $index in either the collection tag or the taxonomy tag, e.g.:

<statamic:collection from="blog">
    <li><a href="{{ $url }}">{{ $index }} {{ $title }}</a></li>
</statamic:collection>
<s:taxonomy from="categories">
  <li><a href="{{ $url }}">{{ $index }} {{ $title }}</a></li>
</s:taxonomy>

$index undefined!

WORKAROUND:

<s:taxonomy from="categories" as="categories">
  @foreach($categories as $index => $category)
    <li><a href="{{ $category->url }}">{{ $index }} {{ $category->title }}</a></li>
  @endforeach
</s:taxonomy>

Logs

Environment

Version: 5.45.2 PRO

Installation

Fresh statamic/statamic site via CLI

Additional details

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions