verbb/hyper

Custom attributes are not rendering

Closed this issue · 5 comments

Describe the bug

So im using the following code to render the button:
{{ entry.button.getLink({class: 'btn btn-dark'}) }}
Which results in
Bekijk de website
With these settings:
Screenshot 2023-07-20 at 09 19 42
It seems our custom attributes setting is somehow overwritten? We want rel="nofollow"

Steps to reproduce

  1. Render a button with the following code: {{ entry.button.getLink({class: 'btn btn-dark'}) }}
  2. Set rel nofollow in the settings.

Craft CMS version

4.4.15

Plugin version

1.1.9

Multi-site?

Yes

Additional context

Dumping the field does shows it does contain the data:

customAttributes: array:1 [▼
    0 => array:2 [▼
      "attribute" => "rel"
      "value" => "nofollow"
    ]
  ]

I can't seem to replicate that, sorry! Here's my details

image image

Produces the following HTML

<a class="btn btn-dark" href="https://github.com/" rel="nofollow">https://github.com/</a>

Is there something different on your end, maybe? I will mention that if you have "New Window" enabled, that will override any custom attributes you have set for rel (we add rel="noopener noreferrer" for links that open in a new window).

Ah sorry, I did another test and i only have this problem with the new window option checked. Without I get a correct output.

Right, that makes sense now! That's an interesting one, as rel attributes aren't treated like class attributes, where they can be merged. We actually just use Craft's normalizeTagAttributes() function to handle that, so we'll need to extend that.

Should be updated for the next release. To get this early run composer require verbb/hyper:"dev-craft-4 as 1.1.9"

Great thanks!

Updated in 1.1.10