1

In my content type I have a thumbnail where I put the link to the image I want to embed into a view.

For the fields I have Content: Title [hidden] Content: Thumbnail

In views for the Content: Thumbnail I check "ReWrite Results" and add

<div class="vid-thumb">
     <img src="http://img.youtube.com/vi/{{ field_thumbnail }}/0.jpg">
</div>
<div class="vid-title">{{ title_1 }}</div>

This displays the YouTube thumbnail in my view. The problem I am having is trying to make it so the user can click on the thumbnail to get to the content instead of having to click on the title which I display below.

I know twig can be used in the "Rewrite Results" but I wasn't sure what to call in there to add it to an href tag

<a href="{{ ???.??? }}"><img src="blah"></a>

1 Answer 1

2

You should be able to select the Path as a field as well. Then use that as a replacement token.

<a href ="{{ path }}"><img src="blah"></a>.

Optionally you can use the title as anchor title or alt attribute, but then you have to make sure to uncheck the "Link to Content" box.

<a href ="{{ path }}" title="{{ title }}"><img src="blah" alt="{{ title }}"></a>.
6
  • I have tried {{ url }}, {{ uri }}, {{ nid }}, {{ node.nid }}, {{ node.uri }}, {{ node.url }} none of them are linking correctly Dec 8, 2015 at 10:49
  • You did load that property as a field first? Dec 8, 2015 at 10:51
  • Ah, apologies, the field is named Path. So in fields, you add path (you can choose to hide it). Make sure it is above the image you are trying to rewrite, order is important. And you can use {{path}} as the token. Dec 8, 2015 at 10:55
  • For some reason when I searched "node" it didn't give me Node ID as an option but when I stopped at "nod" it showed up trying that now... and I just saw your second comment Dec 8, 2015 at 10:56
  • Path is more versatile as it can contain aliases for pretty links etc. Dec 8, 2015 at 10:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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