I'm trying to create my 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 simply reads the file with fread. I'd like to call the image from twig in this way
<img class="user-photo" src="{{ userThumbImg() }}" alt="" />
but I get a binary string. what can I do to display the image in my template? I haven't tried to return a response because this is not a controller, should I have to do in that way?
thanks