Twig icon indicating copy to clipboard operation
Twig copied to clipboard

Add syntax for destructuring assignment

Open hason opened this issue 5 years ago • 1 comments

Add destructuring assignment syntax that makes it possible to unpack values from arrays, or properties from objects, into distinct variables (as same is in Javascript):

A twig template

{% set [a, b] = [1, 2] %} 
{% for {id, firstName, ...rest} in data %}
{% endfor %}

should be converted to

[$a, $b] = [1, 2];
foreach ($data as ['id' => $id, 'firstName' => $firstName]) {
    // TODO support for ...rest
}

hason avatar Sep 23 '20 00:09 hason

Is there any plan to include this is the near future? I would really like to use it

Anubarak avatar Nov 18 '21 13:11 Anubarak