Add a class to link helper

How can I add a class to the link helper?
I added an array, but each array-element gets added to the link as a numberd attribute:
<a href="..bla.." 0="class" 1="color-red-600">bla</a>

        <?php foreach ($site->children()->listed() as $item): ?>
          <?= $item->title()->link(["class", "color-red-600"]) ?>
        <?php endforeach ?>

Should be an array of key/value pairs:

<?php foreach ($site->children()->listed() as $item): ?>
  <?= $item->title()->link(["class" => "color-red-600"]) ?>
<?php endforeach ?>
1 Like

:+1: that works.

I tried to find the answer in the references, did only find that:

Because the field method is called toLink() (link() is only an alias for backwards compatibility):

ok, I literally used the code from the starterkit (snippet.php header nav links), maybe toLink() should be used there as well …

Yes, link() is not wrong, but it doesn’t appear in the documentation because it’s just an alias. Don’t know if “they” plan to remove it or not. If so, the Starterkit should be changed.