phug-php / phug

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

Mixin attributes does not override existing attributes #86

Closed char101 closed 2 years ago

char101 commented 2 years ago

Hello,

I encountered an issue with the following code:

mixin btn()
  a(href='#')&attributes($attributes)

+btn()(href='/')

I expected to get:

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

But I actually get:

<a href="#"></a>

I have tested it with pugjs, and with pugjs, the values in attributes do override existing attributes.

Thanks!

kylekatarnls commented 2 years ago

Hello, you can work around this issue using the explicit way:

PHP style:

mixin btn()
  a(href=$attributes['href'] ?: '#')&attributes($attributes)

+btn()(href='/')

JS style:

mixin btn()
  a(href=attributes.href || '#')&attributes(attributes)

+btn()(href='/')

I will inspect this. Thanks.

kylekatarnls commented 2 years ago

You can now update to the latest version (phug/phug 1.9.0) to get the proper precendence.