Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nav tag recursive children not passing variable #8565

Closed
miicah opened this issue Aug 10, 2023 · 1 comment · Fixed by #8725
Closed

Nav tag recursive children not passing variable #8565

miicah opened this issue Aug 10, 2023 · 1 comment · Fixed by #8725
Assignees

Comments

@miicah
Copy link

miicah commented Aug 10, 2023

Bug description

Variables created outside a recursive children nav loop and referenced inside it, 'hold' the original value instead of changing it. I've used letters here as it's a bit easier to see, but in our real code we are using ints; the same issue occurs.

Navigation

My basic 'main' nav I created is here.

Antlers

The actual antler code is basically copy/pasted from the docs and is a simple recursive children loop.

        <nav>
            {{ counter = "z" }}
            
            {{ nav handle="main_nav" }}
                {{ if depth == 1 }}
                    <div class="mx-10">
                        <h3 class="mb-2">{{ title }} - {{ counter }}</h3>
                        {{ if children }}
                            <ul>{{ *recursive children* }}</ul>
                        {{ /if }}
                        
                    </div>
                {{ elseif depth == 2 }}
                    <li class="px-2 my-1">
                        <a href="{{ url }}">{{ title }} - Child of {{ counter }}</a>
                    </li>
                {{ /if }}

                {{ counter += "a" }}
            {{ /nav }}
        </nav>

Result:

Screen Shot 2023-08-11 at 9 03 35 am

Expected result:

Screen Shot 2023-08-11 at 9 14 19 am

How to reproduce

  1. Open a nav tag pair
  2. Use and then increment a variable
  3. Have recursive children
  4. The variable used in the recursive children is the original value, not the incremented one

Logs

No response

Environment

Environment
Application Name: Statamic
Laravel Version: 10.18.0
PHP Version: 8.2.8
Composer Version: 2.5.8
Environment: local
Debug Mode: ENABLED
URL: localhost
Maintenance Mode: OFF

Cache
Config: NOT CACHED
Events: NOT CACHED
Routes: NOT CACHED
Views: CACHED

Drivers
Broadcasting: log
Cache: statamic
Database: mysql
Logs: stack / single
Mail: smtp
Queue: sync
Session: file

Statamic
Addons: 0
Antlers: runtime
Stache Watcher: Enabled
Static Caching: Disabled
Version: 4.16.0 Solo

Installation

Starter Kit using via CLI

Antlers Parser

regex (default)

Additional details

No response

@miicah
Copy link
Author

miicah commented Aug 10, 2023

I also tried

If your scoped variables have trouble making it through to the next recursion, you can glue them to children like this: {{ recursive children:my_scoped_variable }}.

But this broke the loop entirely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants