phug-php / phug

Phug - The Pug Template Engine for PHP
https://phug.selfbuild.fr
MIT License
63 stars 3 forks source link

Breaking change 1.8 -> 1.9 of `a(href=$url)&attributes($attribs)` #88

Closed rulatir closed 1 year ago

rulatir commented 2 years ago

Hello,

I encountered a breaking change between 1.8 and 1.9:

a(href=$url)&attributes($attribs)

Assuming $url === "foo" and $attribs['href'] === "bar", in 1.8 I got:

<a href="foo"></a>

But in 1.9 I get:

<a href="bar"></a>

Looks like in 1.8 explicitly specified attributes took precedence over the attributes bag, but in 1.9 it's just left-to-right, last one wins.

kylekatarnls commented 2 years ago

Hello,

This fix is related to #86 with the aim to align to pugjs and to support the automatically seeded $attributes array (coming from explicit attributes passed to the mixin call).

I think you could use:

mixin link()
  - unset($attribs['href'])
  a(href="#")&attributes($attribs)

link()(href="/")

This way you explicitly show that you ignore href from $attribs and you would get the desired output.

rulatir commented 1 year ago

Is there a solution that doesn't require fixing a hundred views in a thousand places, each requiring careful consideration and debugging? Is it possible to write something that will do what &attributes() used to do, and search/replace all occurrences of &attributes() with it?

kylekatarnls commented 1 year ago

Hello, in the next version (can be already tested requiring composer require "phug/phug:dev-master as 1.12.0"), the option 'attribute_precedence' => 'attribute', can be used to give precedence to attributes over assignments, or 'attribute_precedence' => 'left', to give priority to the most-left token.