symfony - Symfony2 - Image uploaded only displays when being called in the Twig file -


i have problem displaying uploaded image web/images when using following line below while inside of blog text or using data fixture.

i've tested manually calling in code display image inside of twig file want use in fixture/entering in blog text customize size/alignment of images each post.

can show me what's preventing image displaying?

cheers!

this refuses display image while in fixture or inside blog text: (shows outline of proper sizing , alignment of image inside blog text not image itself)

<img class="alignleft" src="{{ asset(['images/', news.image]|join) }}" alt="" width="290" height="275" /> 

using web link image works fine when in fixture or when entering blog text:

<img class="alignleft" src="http://www.example.com/example.jpg" alt="" width="290" height="275" /> 

using autoescape false display blog text:

{% autoescape false %}    <p>{{ news.blog }}</p> {% endautoescape %} 

you're trying render string(variable) (sub-)template.

that's why twig isn't processing {{ asset() }} function.

auto-escaping not you're looking doesn't enable processing of twig functions inside strings.

solution: the template_from_string function

1.) enable twig_extension_stringloader extension comes bundled twig in config.yml

services:     # ...     twig.extension.stringloader:         class: twig_extension_stringloader         tags:             - { name: twig.extension } 

now clear cache using app/console cache:clear.

2.) if have template stored in variable named news.blog can use function follows:

{{ include(template_from_string(news.blog)) }} 

more information in documentation: template_from_string


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -