based on this post
I am trying to check if a remote image exists (loads correctly), and if it does, display it, othervise display default image. I have already done a twig extension and corrected the code but it always returns false though I definetely know that the image exists. My twig template code is as follows:
{% if file_exists(author.image) %} //always get false here so the default image is loaded
<img src="{{ author.image }}" alt="{{ author.name }}">//loads an image correctly if outside condition
{% else %}
<img src="/var/www/web/img/no_image.png" alt="no_image">
{% endif %}
Any help is appreciated. Thank you.
UPD My twig function is as follows:
<?php
namespace AppBundle\Twig\Extension;
class FileExtension extends \Twig_Extension
{
/**
* Return the functions registered as twig extensions
*
* @return array
*/
public function getFunctions()
{
return array(
new \Twig_SimpleFunction('file_exists', 'file_exists'),
);
}
public function getName()
{
return 'app_file';
}
}