Reputation: 165
i want to load an image in my twig but it doesnt show anything only show picture alt
this is my list.html.twig that will load image:
<img src="{{ asset('images/2.jpg') }}" alt="Symfony" />
and this is my controller :
<?php
namespace AppBundle\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
class InheritanceController extends Controller
{
/**
* @Route("/inherit")
*/
public function inheritAction(){
return new Response($this->render('article/list.html.twig'));
}
}
my image folder is in root directory
Upvotes: 0
Views: 13114
Reputation: 53
The method $this->render()
already returns a Response
instance, just change it toreturn $this->render(...)
and try again.
Upvotes: 0
Reputation: 737
You can use asset()
function in twig with its default configuration only when your images exists on web/images
folder, then you can make a call to any image by {{ asset('images/<image_name>') }}
Upvotes: 0
Reputation: 1431
Install assets via console: php app/console assets:install --symlink
Upvotes: 0