Pregunta

I have a paragraph field that is a reference entity to the Customer Testimonial content type. A content editor can add the customer-testimonial paragraph and type the name of the testimonial. This will then display the text on the website.

I have made a paragraph--c15a-customer-testimonial.html.twig template file with the following code.

{%
  set c15a = {

    title: content.field_testimonial.entity.field_testimonial_titel,

  }
%}

<div class="component c15a">
    <div>

        <div>Testimonial title</div>

        <h2>{{ c15a.title }}</h2>

    </div>
</div>

Of course, this prints nothing. How can I get the fields from the content type I'm referencing in my paragraph?

¿Fue útil?

Solución

The referenced entity is not built yet, so you can't access the formatted field content.

You can get the field value from the database by using the paragraph object:

{{ paragraph.field_testimonial.entity.field_testimonial_titel.value }}

This is unformatted, which might work for a title field.

If you want a formatted output better use a custom view mode for the referenced entity to configure the fields, or in this case one field, if this is all you want to display.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a drupal.stackexchange
scroll top