Comments (5)
Doh, should have thought to test on Twig Fiddle. I tested locally with a simple hash/array:
{% set hash = {
one: 1,
two: 2,
} %}
{% dd {
...hash,
three: ['four'],
} %}
#}
And that worked fine, so I figured it was a Twig bug with arrays that come from object methods.
Fixed for the next release!
from cms.
Craft 4.8.10 and 5.0.5 are out with that fix. Thanks for reporting!
from cms.
That’s something you’ll need to report on the Twig repo.
from cms.
@brandonkelly I don't think this is a Twig issue. I've tried to replicate the problem on Twig Fiddle. This here works fine: https://twigfiddle.com/ovw4ri
This outputs the expected result:
one: two
baz: bat
However, if I put this in a Twig template in my Craft project:
{% set key = { "nested": { one: "two" }} %}
{% set merged = {
...attribute(key, 'nested'),
baz: 'bat',
} %}
{% dd merged %}
I get an incorrect result again:
So it's probably something that Craft is doing, or am I missing something?
Update: This is the compiled template:
// line 3
$context["key"] = ["nested" => ["one" => "two"]];
// line 4
echo "
";
// line 5
$context["merged"] = [craft\helpers\Template::attribute($this->env, $this->source, // line 6
(isset($context["key"]) || array_key_exists("key", $context) ? $context["key"] : (craft\helpers\Template::fallbackExists("key") ? craft\helpers\Template::fallback("key") : (function () { throw new RuntimeError('Variable "key" does not exist.', 6, $this->source); })())), "nested"), "baz" => "bat"];
Definitely looks to me like it's related to one of Craft's node visitors, similar to #14783
from cms.
@brandonkelly Tricky Bug 🐛 Thanks for the fix!
from cms.
Related Issues (20)
- [5.x]: When using editableTableField, with autosuggest and suggestEnvVars, the dropdown only appears on first table row
- [5.x]: Aliasing of fields in field layout doesn't work HOT 5
- [5.x]: SVGs are considered "Images" HOT 7
- [5.x]: 0 added to all empty fields HOT 4
- [5.x]: Upgrade from Craft 4 deletes all text fields HOT 4
- [5.x]: Error on the edit page for created assets by asset index utility from files with spaces in filename HOT 8
- [5.x]: Collapsing the bottom entry in a structure appends "Nothing yet" to the index view HOT 2
- [5.x]: Unusable Icons Displayed in Icon Field HOT 3
- [5.x]: The "Edited" tag in the breadcrumbs bar disappears on page reload HOT 2
- [5.x]: Dropdown field marked as dirty when opening slideout HOT 6
- [5.x]: Unable to Add the Same Image Field Multiple Times HOT 3
- [4.x]: Search index algorithm not functioning as expected HOT 1
- [5.x]: Sidebar overlap with entry index in some screen widths HOT 1
- [5.x]: Craft 4 to 5 staging deploy fails with "Unknown column 'fields.groupId' in 'field list'" HOT 1
- [5.x]: Nested matrix entry types disappear when page is reloaded after making changes HOT 2
- [4.x]: `Entry::EVENT_AFTER_SAVE` executes before any changes are committed to the database HOT 3
- Disappearing Assets HOT 1
- [5.x]: Entry Condition not working properly on Matrix fields. HOT 1
- [5.x]: postgres exception during upgrade from v4 to v5 HOT 5
- Element Editor Slide Out - Will Not Save Updates [4.9.6]: HOT 17
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cms.