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

Leakage or not leakage? Of view variables in antlers partials with frontmatter #11486

Open
sosias opened this issue Feb 21, 2025 · 0 comments
Open
Labels

Comments

@sosias
Copy link

sosias commented Feb 21, 2025

Bug description

In antlers, with partials including partials, the frontmatter nested variables leak to the parent on the second include of the same partial. Or is this not a leak, and is this the expected behavior?

How to reproduce

In a new statamic project add these 3 antlers files:

resources/views/_partial_a.antlers.html

---
var_partial_a: 'var_part_A'
---

<div>
  INSIDE_PARTIAL_A(
    {{ view.var_partial_a }}
    {{ view.var_partial_b }}
  )
</div>

resources/views/_partial_b.antlers.html

---
var_partial_b: 'var_part_B'
---

{{ partial:partial_a :param="param" /}}

<div>
  INSIDE_PARTIAL_B(
    {{ view.var_partial_a }}
    {{ view.var_partial_b }}
  )
</div>

resources/views/home.antlers.html

<div style="border: 1px solid black; padding: 1rem;">
------------- TEMPLATE --------------

<div style="border: 1px solid black; padding: 1rem;">
  ------------- PARTIAL_B--------------
  {{ partial:partial_b /}}
  ------------- /PARTIAL_B-------------
</div>
<div>
  INSIDE_TEMPLATE(
    {{ view.var_partial_a }}
    {{ view.var_partial_b }}
  )
</div>

<div style="border: 1px solid black; padding: 1rem;">
  ------------- PARTIAL_B--------------
  {{ partial:partial_b /}}
  ------------- /PARTIAL_B-------------
</div>
<div>
  INSIDE_TEMPLATE(
    {{ view.var_partial_a }}
    {{ view.var_partial_b }}
  )
</div>

------------- /TEMPLATE -------------
</div>

In the browser visit the url that renders the template file resources/views/home.antlers.html.

This will be the rendered view:

Image

In the template file _home.antlers.html, it seems that the first occurrence of the partial {{ partial:partial_b /}} removes the view variables on each nested partial exit. However in the second occurrence of the partial {{ partial:partial_b /}} the view variable var_partial_a is still present in the nested partial view.
When we returned to the template file, all view variables were correctly removed.
However (not shown in the case above) but in the layout file that contains the template, both variables are present again var_partial_a and var_partial_b.

Logs

Environment

Environment
Application Name: Statamic
Laravel Version: 11.43.2
PHP Version: 8.3.12
Composer Version: 2.8.2
Environment: local
Debug Mode: ENABLED
URL: statamic_empty_project.test
Maintenance Mode: OFF
Timezone: UTC
Locale: en

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

Drivers
Broadcasting: log
Cache: file
Database: sqlite
Logs: stack / single
Mail: log
Queue: sync
Session: file

Statamic
Addons: 1
Sites: 1
Stache Watcher: Enabled (auto)
Static Caching: Disabled
Version: 5.x-dev Solo

Statamic Addons
statamic/ssg: 3.1.0

Installation

Fresh statamic/statamic site via CLI

Additional details

No response

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

No branches or pull requests

2 participants