0

I cannot get this to render out. This is what I get with {{ kint(paragraph.field_image.value) }}.

screenshot

If this makes any difference, the image is uploaded through a media entity browser widget.

How do I render an image from a Twig template?

2

you could just use {{ content.field_image }}

Here is an example of a template file from a paragraph

{%
  set classes = [
  'paragraph',
  'paragraph--type--' ~ paragraph.bundle|clean_class,
  view_mode ? 'paragraph--view-mode--' ~ view_mode|clean_class,
]
%}
{% block paragraph %}
<div{{ attributes.addClass(classes) }}>
  {% block content %}
      <div class="row collapse expanded mainsection">
        <div class="large-12 columns">
          <div class="row collapse">
            <div class="large-12 columns">
              {{ content.image }}
            </div>
          </div>
        </div>
      </div>
  {% endblock %}
  </div>
{% endblock paragraph %}

Notice that I only need to write {{ content.FIELDNAME }}, if I wrap everything in a {% block content %}

  • I'm still learning what the meaning of blocks are in twig templates, I have seen them in template files but this was new to me, thanks for sharing. – drupalhgy Mar 24 '18 at 19:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.