Page variables override parameters passed to partials #1189
Comments
The issue persist in 2.5.2, and the same work-around can still be applied in the code. Favoring the parameters array over the context array to make sure any explicitly listed parameters do get used. |
Should front matter in partials override passed params? This is not the behavior in previous releases, but it is now with 2.5.3. I've been using front matter to set defaults that I can override when I call the partial. Given this partial: ---
p_cta_class: button
---
<a href="{{ p_url }}" class="{{ p_cta_class }}">{{ p_cta_text }}</a> This template: {{ partial:cta p_cta_class="button v-white" }} The output is: <a href="/support-us/corporate-sponsor" class="button">In reprehenderit</a> |
Are you using 2.5.3? |
Yes. |
I added this (probably after you read your notification):
|
Yeah I don't think I saw that. Anyway, it should work as you expect. Just tested here and works fine. Hmm. 🤔 |
I misread that comment, and implemented it incorrectly. One too few cups of coffee. Fixed for 2.5.4 To clarify the cascade:
In 2.5.3, number 2 and 3 were mixed around. |
this can be closed I think, right @jasonvarga? |
Expected behaviour
Passing explicit parameters to partials should override any page variables of the same name.
This would also be consistent with the general idea of the cascade, to have more specific data override the "top-level" data.
Actual behaviour
Passing variables to a partial that have a page-level equivalent is ineffective, and the top level page variable is always sourced.
Steps to reproduce
partials/header.html:
<h1>{{ title }}</h1>
{{ partial:header title="Foo Bar" }}
Server configuration
Operating system:
Windows 10
Web server:
Apache 2.4
PHP version:
5.6.29
Statamic version:
2.1.19
Updated from an older Statamic or fresh install:
Fresh install
List of installed addons:
None
Solution
This behavior can be mitigated in PartialTags::__call by swapping the operands to the array_merge call in line 32, so that the original contents of the $variables array is preserved over the context content.
The text was updated successfully, but these errors were encountered: