I'm using Drupal 8 and building a view
. I have a field, which happens to be a title
field, and I have set it to link to content
. I would like to know how I can simply add a btn
class to the anchor
tag. Right now the output looks like this:
<a href="/node/{id}" hreflang="en">... custom text ...</a>
I know I can use the Rewrite Results
view feature to accomplish this, however, I need more power than that because I am building a theme for a client. The theme needs to be more generic, so I need to be able to accomplish this in a template. Is there template suggestion/hook that would allow me to override this in a template such as .../templates/views-view-field--link.html.twig
? Or is there a theme function that I could use to override the markup by adding the class I would like?
I've considered using the views-view-field.html.twig
template and overriding the node_view
type to accomplish this, but I'm not sure how to do that whilst keeping the custom text a user could be using because it's really hard to debug the field
options.
Edit
I forgot to mention, this needs to rely on Drupal core
. I can't expect the user to install any additional modules for it to work.
core
and can't expect the client or user to install any additional modules, but thanks for your suggestions. Perhaps I can learn from how they've done it in their module.