repincln
repincln

Reputation: 2059

save sonata media path into twig variable

I want to store full path of image (sonata media bundle) into variable in twig. Is that possible?

If I write:

{% set pic = path item.image, 'big' %}

it throws me an error: Unexpected token "name" of value "item" ("end of statement block" expected) ...

If I write:

{% set pic = item.image %}

then it works, but it stores only name of the file, not full path.

Upvotes: 6

Views: 1634

Answers (3)

lefakir
lefakir

Reputation: 4031

Why don't you do like this ?

{% set rendered %}{% path item.image, 'big' %}{% endset %}
....
Here is my path {{ rendered }}

Upvotes: 7

user511564
user511564

Reputation: 376

Perhaps you can solve with:

<img src="{% path media, 'small' %}" data-href="{% path media, 'big' %}">

Upvotes: 0

Wouter J
Wouter J

Reputation: 41954

There is not such a function available (there is a path() function to generate routes). You have to create your own twig extension with this custom function. Read all about that in the documentation.

Upvotes: 1

Related Questions