how to call fields in paragraphs with Inline Formatter Display

Created on 25 February 2023, almost 2 years ago
Updated 8 March 2023, almost 2 years ago

Problem/Motivation

For example, I have a paragraph with a links field and I want to write the output using twig with this module, but I can't find the way to call the fields. I could already do it with tokens, but I would like to see if it can be done with, for example, {{field.field_link } } or something like that

Steps to reproduce

- Install module Inline Formatter Field
- Install module Paragraphs
- Create paragraphs and add field link
- Enter to manage display and enable check Inline Formatter Display
- Create twig and call fields

πŸ“Œ Task
Status

Closed: works as designed

Version

3.1

Component

Documentation

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 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 almost 2 years ago
  • πŸ‡ΊπŸ‡Έ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 almost 2 years ago
  • πŸ‡ΊπŸ‡ΈUnited States bobbysaul
Production build 0.71.5 2024