symfony - Symfony2: how to make a twig extension return an image -


i'm trying create first twig estension

class userextension extends \twig_extension { public function getfunctions() {     return array(         new \twig_simplefunction('userthumbimg', array($this, 'getuserthumbimg')),     ); }  public function getuserthumbimg() {     $thumbimage = repository::getinstance('users')->getuserimg(4, true);     return $thumbimage['image']; }  public function getname() {     return 'user_extension'; } } 

the static repository class reads file fread. i'd call image twig in way

<img class="user-photo" src="{{ userthumbimg() }}" alt="" /> 

but binary string. can display image in template? haven't tried return response because not controller, should have in way?

thanks

you use path display image. save image somewhere on server , return path. or transform image in data: link , return that.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -