- Issue created by @Nelo_Drup
- πΊπΈUnited States bobbysaul
Hello,
Here is a link to common twig patterns I've used when working with twig:
https://www.drupal.org/docs/contributed-modules/inline-formatter-field/c... βThe answer to your questions depends on where you are writing the twig. For example, if I am writing the twig from a node that has a reference field to a paragraph which contains a link field the twig could look something like:
{% for paragraph in node.field_paragraph %} {{ paragraph.entity.field_link|view }} {% endfor %}
if you have the Twig Tweak module. Or, for more granule output it could be something like:
{% for paragraph in node.field_paragraph %} {% if paragraph.entity.field_link %} <a href="{{ paragraph.entity.field_link.0.url }}">{{ paragraph.entity.field_link.title }}</a> {% endif %} {% endfor %}
If you are writing the twig from the paragraph types display then it would look more like:
{{ paragraph.field_link|view }}
if you are using the Twig Tweak module. Or for a more granule output something like:
{% if paragraph.field_link %} <a href="{{ paragraph.field_link.0.url }}">{{ paragraph.field_link.title }}</a> {% endif %}
Notice that in the paragraph entity type we can access the current entity with the context "paragraph" whereas in the node content type the entity was referenced with the context "node". The entity type will determine the context. And chaining into entities referenced in an entity reference field can be done by using ".entity" after nesting into the field (see the example from the node entity).
Hopefully, this will help out!
- Status changed to Postponed: needs info
over 1 year ago 2:11am 4 March 2023 - πΊπΈUnited States bobbysaul
Hello, Does the previous comment help? Is this task ready to be closed?
#3 Hello, yes I just understood that I should use the for loop, since the tokens are pasted directly I assumed it was something like that, but thanks for the explanation
- Status changed to Closed: works as designed
over 1 year ago 12:09am 8 March 2023