4

This code:

{{ foo.getLink() }}

Outputs this:

<a href="URL_HERE">NAME_OF_PAGE</a>

What I really want is something like:

<a href="URL_HERE" class="bar">NAME_OF_PAGE</a>

Is it possible to set "class" and/or other html attributes when using Craft CMS Entry Property getLink()?

Luke Pearce
  • 3,863
  • 1
  • 11
  • 25
Beau Smith
  • 143
  • 4

2 Answers2

9

No, getLink outputs a very simple version of the link.

If you want something more complex, you'll need to build it manually...

<a href="{{ foo.url }}" class="bar">{{ foo.title }}</a>
Lindsey D
  • 23,974
  • 5
  • 53
  • 110
0

Try LinkIt. Allows you to set attributes. https://github.com/fruitstudios/LinkIt/blob/master/README.md

shorn
  • 438
  • 2
  • 9