1

I have a view that uses one field to produce a list of links to content.

I want to add a 'title' attribute to the link produced by the view that takes its value from a different field.

How does one do this in Drupal 8?

1

Thanks to zhilevan for pointing me in the right direction. After much trial and error this is the only thing I got to work other than completely rewriting the input with custom html.

  1. I needed to add a "path to content" field. Note my fields are called 'field_heading' and 'title' respectively.

enter image description here

Note: the field that will actually host the link has to be at the bottom of the list. I wasted ages trying to figure out why I couldn't target my title text before realising this...

  1. You need to uncheck "Link to content" in the setting for the host field - in my case 'Heading'

enter image description here

  1. In the 'Rewrite output' section you need to actually provide a link or it will not work - or at least I could not get it to work without it. So the 'path' field I added earlier was used here as the path for the link. I could then add title field to the title attribute. You can see the available replacement patterns in the drop down with that name.

enter image description here

and the title attribute override...

enter image description here

Anyhoo, that was what i had to do to get it to work. Hopefully it is useful to someone else. I would love to see a simpler way to do this.

0
1

You can achieve this by using views Rewrite results feature, Rewrite your Link with checking Override the output of this field with custom text and put your markup there and with Replacement patterns put your title as your link attribute title.

More details Provided by @Raf

Thanks to zhilevan for pointing me in the right direction. After much trial and error this is the only thing I got to work other than completely rewriting the input with custom html.

  1. I needed to add a "path to content" field. Note my fields are called 'field_heading' and 'title' respectively.

enter image description here

Note: the field that will actually host the link has to be at the bottom of the list. I wasted ages trying to figure out why I couldn't target my title text before realising this...

  1. You need to uncheck "Link to content" in the setting for the host field - in my case 'Heading'

enter image description here

  1. In the 'Rewrite output' section you need to actually provide a link or it will not work - or at least I could not get it to work without it. So the 'path' field I added earlier was used here as the path for the link. I could then add title field to the title attribute. You can see the available replacement patterns in the drop down with that name.

enter image description here

and the title attribute override...

enter image description here

Anyhoo, that was what i had to do to get it to work. Hopefully it is useful to someone else. I would love to see a simpler way to do this.

3
  • Do you mind pointing me to an example? Rewrite seems to be doing nothing for me when I try edit the title field.
    – tanbog
    Mar 14 '17 at 6:57
  • @raf you're welcome, sorry for late answer I was away.
    – Yuseferi
    Mar 14 '17 at 8:32
  • @raf because your answer is the same of mine remove this answer please. I add the details provided by you to my answer.
    – Yuseferi
    Mar 14 '17 at 8:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.