1

I'm trying to print out the url path of a node from a referenced entity paragraph field in my twig template however have not had any success so far. I have tried various common twig functions but with no luck.

Any ideas?

2

1 Answer 1

4

Use the Twig path() function and build a node route with the target id of the reference field:

paragraph.html.twig

{% if paragraph.field_example.target_id %}
  <a href="{{ path('entity.node.canonical', {'node': paragraph.field_example.target_id}) }}">{{ 'View node page'|t }}</a>
{% endif %}

See https://www.drupal.org/docs/8/theming/twig/functions-in-twig-templates

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.