Drupal 8 twig: Get the fields from a reference entity (content type) in a Paragraph field

drupal-8twig

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?

Thx,

Best Answer

I'm not 100% certain, but can you try this:

{% set c15a = { 'title': {{ content.field_testimonial.entity.field_testimonial_titel }} } %}

Adding the double brackets around the variable passed in.

Related Topic