How to get image path in branch using SonataMediaBundle?

I use SonataMediaBundle to track my images. I can display the image in the branch using the sonata helper:

{% media user.profilepic, 'reference' %}

This will be displayed in <img src="the src">

But what I want to get is a bare way, so I can, for example, add a class to my img. Sort of:

<img class="img-responsive" src="{{ asset(user.profilepic) }}">

Obviously, it asset(user.profilepic)does not return the path, but the object and this object do not contain the path to the image.

EDIT

Also found part of my answer:

{% set foo %}
     {% path image, 'small' %}
{% endset %}
<img src="{{ asset(foo) }}" alt=""/>

Apparently, the output of the block can be set to a variable, and then pass this to the asset function.

+4
source share
1 answer

.

{% media media, 'small' with {'class': 'myclass'} %}

"":

{% path media, 'small' %}
+4

Source: https://habr.com/ru/post/1611953/


All Articles