statamic / v2-hub

Statamic 2 - Feature Requests and Bug Reports
https://statamic.com
95 stars 5 forks source link

[BUG] Index scoping failure #2394

Open sjclark opened 5 years ago

sjclark commented 5 years ago

Describe the bug {{index}} function doesn't increment correctly when scoped

To Reproduce Steps to reproduce the behavior:

{{ collection:blog scope="foo" }}
  <p>index - {{ foo:index }} - {{ date }}<a href="{{ url }}">{{ title }}</a></p>
{{ /collection:blog }}

This case fails to increment the index

Expected behavior

{{ collection:blog }}
  <p>index - {{ index }} - {{ date }}<a href="{{ url }}">{{ title }}</a></p>
{{ /collection:blog }}

This case correctly increments index

Environment details (please complete the following information):

Additional context Discussed this with Erin on Statamic Discord (who provided the minimum test examples above) - seems to be a bug with Scope not working for Index. In my text case I wanted to have an index multiple times within a loop, but incrementing a level higher in the code.

My specific example:

{{ collection:pastshows scope="loop"}}
<div class="columns is-variable is-8">

    <div class="column is-4">
        {{ assets:show_images }}
        {{if first}}
        <a href="{{ url }}" data-fancybox="gallery-{{loop:index}}">
            <img src="{{ glide:url width="500" height="300" }}">
        </a>
        {{else}}
        <a href="{{ url }}" data-fancybox="gallery-{{loop:index}}"></a>
        {{/if}}
        {{ /assets:show_images }}
    </div>
</div>
<hr>
{{/collection:pastshows}}

This should increment the {{loop:index}} every time a new pastshows record iterates, but instead it increments within the scope.