Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 851
repincln Avatar asked Nov 03 '14 20:11

repincln


2 Answers

Why don't you do like this ?

{% set rendered %}{% path item.image, 'big' %}{% endset %}
....
Here is my path {{ rendered }}
like image 86
lefakir Avatar answered Oct 04 '22 23:10

lefakir


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.

like image 40
Wouter J Avatar answered Oct 05 '22 00:10

Wouter J