0

How do I display an image in Twig loaded from a Doctrine Fixture that I've uploaded to the web/images folder? It displays when calling it from the acutal Twig but not from fixtures or entering the line when creating the blog text.

I have tried this line which doesn't load when in a fixture file (or inside the blog body when creating the blog entry) BUT when I use this line inside of the actual Twig file it does the image correctly?

<img src="{{ asset(['images/', blog.image]|join) }}" />

Using this to display the blogs in twig:

{% autoescape false %}
    <p>{{ blog.blog|truncate(2000) }}</p>
{% endautoescape %}
dizzyd
  • 201
  • 1
  • 7
  • 15

2 Answers2

0

I think your missing a quote mark in example 2

try changing:

<img class="alignleft" src="{{ asset('images/5375a30370200.jpeg) }}" alt="" width="290" height="275" />

to: <img class="alignleft" src="{{ asset('/images/5375a30370200.jpeg') }}" alt="" width="290" height="275" />

Or set a new variable

{% set src = 'images/' ~ blog.image %} <img class="alignleft" src="{{ asset( src ) }}" alt="" width="290" height="275" />

http://twig.sensiolabs.org/doc/tags/set.html

Joe
  • 2,981
  • 1
  • 16
  • 17
  • Sorry I didn't get a chance to add more information before the site went down. See updated question. – dizzyd May 16 '14 at 21:30
  • Tried both your solutions, they still do not load from a data fixture file or when creating the blog text manually and adding the code in. – dizzyd May 16 '14 at 21:58
0

Turns out I have to use Twig's template_to_string function.

dizzyd
  • 201
  • 1
  • 7
  • 15