phug-php / phug

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

Support for named arguments in mixins #93

Closed McSodbrenner closed 1 year ago

McSodbrenner commented 1 year ago

It would be great if named arguments from PHP 8 (https://www.php.net/manual/en/functions.arguments.php#functions.named-arguments) could be supported when using mixin arguments. This would extremely simplify the parameter handling of mixins with many optional parameters.

kylekatarnls commented 1 year ago

Hello, you can use attributes:

PHP-style expressions:

mixin test
  p=$attributes['text']
  a(href=$attributes['url'])=$attributes['link']

+test(text="Hello" link="Click me" url="https://phug-lang.com")

JS-style expressions:

mixin test
  p=attributes.text
  a(href=attributes.url)=attributes.link

+test(text="Hello" link="Click me" url="https://phug-lang.com")

If it does not fit your need, please provide an example of something that cannot be achieved with attributes.

It might also be possible to create a plugin for that.