Skip to content

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

Open
@sosias

Description

@sosias

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

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