Closed acalvino4 closed 2 years ago
I'm pretty sure the docs are wrong, as it should be exactly as you describe:
{{ node.linkAttributes({
class: "text-base text-gray-500",
id: "a-heading",
...
}) }}
That should work - apart from merging attributes defined in the node, which is fixed in 1.4.25
Thanks, I'll try it out! Thanks for such a fast response!
Description Using
node.linkAttributes
with additional attributes does not render expected markupSteps to reproduce
{{ node.linkAttributes([{attribute: 'class', value: "text-base text-gray-500 hover:text-gray-900"}]) }}
in twig template as directed by the documentation.class="" href="https://example.com/url/path" 0='{"attribute":"class","value":"text-base text-gray-500 hover:text-gray-900"}'
output into your markup.Expected Behavior Observe
class="text-base text-gray-500 hover:text-gray-900" href="https://example.com/url/path"
output in my markup.Additional info
Additional context Since I know
linkAttributes
already injects aclass
attribute based on cp contents (as evidenced byclass=""
in the output above), I tried this using a different attribute and got the same result. So it seems there is either a bug or the documentation is incorrect.As a side note, a much nicer syntax for this would be
since it avoids the verbosity and confusion of
([{
, and the verbosity ofattribute
andvalue
in there. Just a thought.Thanks for looking into this!