Giter Site home page Giter Site logo

Comments (5)

brandonkelly avatar brandonkelly commented on July 3, 2024 1

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.

brandonkelly avatar brandonkelly commented on July 3, 2024 1

Craft 4.8.10 and 5.0.5 are out with that fix. Thanks for reporting!

from cms.

brandonkelly avatar brandonkelly commented on July 3, 2024

That’s something you’ll need to report on the Twig repo.

from cms.

MoritzLost avatar MoritzLost commented on July 3, 2024

@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:

Screenshot 2024-04-22 at 09 56 54

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.

MoritzLost avatar MoritzLost commented on July 3, 2024

@brandonkelly Tricky Bug 🐛 Thanks for the fix!

from cms.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.