Joker / jade

Jade.go - pug template engine for Go (golang)
BSD 3-Clause "New" or "Revised" License
354 stars 37 forks source link

Mixins attributes not supported #46

Open Panakotta00 opened 2 years ago

Panakotta00 commented 2 years ago

I tried to use the attribute parameter of mixins. That parameter seems to not be supported.

I tried to use code like:

mixin listRow(name, link)
    tr&attributes(attributes)
        td= $name
        td= $link
+listRow("some name", "some-link.com")(hx-swap-oob="beforeend:#list-table")

It should create some html like:

<tr hx-swap-oob="beforeend:#list-table">
  <td>some name</td>
  <td>some-link.com</td>
</tr>

for the mixin I also tried

mixin listRow(name, link)
    tr&attributes($attributes)
        td= $name
        td= $link

but that did not work either.

Is there another way to implement this or are there plans to fix it?

ljluestc commented 1 year ago
mixin listRow(name, link, customAttributes)
  tr&attributes(customAttributes)
    td= name
    td= link

Then, when you use the mixin, you can pass the customAttributes parameter like this:

+listRow("some name", "some-link.com", {"hx-swap-oob": "beforeend:#list-table"})

This should help you achieve the desired HTML output with the additional custom attribute.