0

Drupal 8 Twig question:

I have 2 fields: textfield and a linkfield.

When the linkfield is filled, the text entered in the textfield should become the link. I cannot edit the node.html.twig for this, I want to do this in the field--textfield.html.twig to include the URL (if it is set).

But I don't know how to make the URL from "field--linkfield.html.twig" available in "field--textfield.html.twig"

(Needed because the link module is still a little bit broken in Drupal 8 (no optional URL possible)).

1 Answer 1

0

If you want to get a field value from another field in a field template you have to use the parent entity (in your case a node) element['#object']:

{{ element['#object'].field_textfield.value }}

or a url from a link field:

{{ element['#object'].field_linkfield.0.url }}
1
  • Perfect! Now I know what to look/learn for in Twig :) thanks a lot! Commented May 23, 2017 at 16:18

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.