4

I have a D8.2.0 website with a view showing unformatted list of content of certain content type. For each item in the content two field values are shown.

I want one of the fields to be a link to the content item node. I used Rewrite Results > Output this field as a custom link and put the following value:

/node/{{ node.id }}

But no luck. I also tried nid. I cannot seem to find a documentation or a blog post that discusses different values that can be used in twig-enabled fields in D8 views.

If possible please add references to documentation or posts that explain what variable names are available in addition to what is the correct way to use the node id by twig.

3 Answers 3

4

If you have option link to content you can check it:

Link to content

Else you can:

  1. Add new field "Content:Path"
  2. Hide this new field from display
  3. Place it before your desired linked field
  4. Rewrite output of field with: <a href="{{ path }}">{{ field_name }}</a>

Step 3 is very important : field rewriting tokens needs to be placed before your field.

4
  • 1
    when I do so, nothing appears at all for the field
    – Bishoy
    Commented Jan 11, 2017 at 12:14
  • 1
    And the link to content is not available, I guess it is only available for title field?
    – Bishoy
    Commented Jan 11, 2017 at 12:15
  • Silly me, all of this time was trying without reading step 3 in your answer, I had the ID field at the end of the list of fields. It is working now, thanks.
    – Bishoy
    Commented Feb 16, 2017 at 9:11
  • what if path is not available and if a link englobing all files is wanted?
    – Matoeil
    Commented Nov 15, 2018 at 15:17
2

Firstly you need to add ID as a hidden field and then for the field you want to have link, just create REWRITE RESULTS for that as shown in below image:

enter image description here

1

If you want to add the link in the html with content text, then use below way. Case1:

  1. Add the content text field.
  2. Add html like( Read Post ) in text. enter image description here

Case 2: If You want add link to the node page without using any html then Add field link to content and add the display text(ead more). enter image description here

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.