Reputation: 392
I know there are similar questions like that, but the errors don't apply to me.
So I'm trying to render a template in my LuckyController.php
file which looks like that:
<?php
namespace App\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class LuckyController extends AbstractController{
/**
*
*@Route("/lucky/number")
*/
public function number(){
$number = random_int(0,100);
return $this->render('lucky/number.html.twig',[
'number' => $number,
]);
}
}
Then, I have the base.html.twig
template that I want to render:
{# templates/lucky/number.html.twig #}
<h1> Your lucky number is {{ number }} </h1>
This is a part of my file structure that could be eventually relevant:
Project
|
--src
|
--Controller
|
-- LuckyController.php
--templates
|
-- number.html.twig
The problem that I have:
Unable to find template "templates/number.html.twig" (looked into: ~\symfony\Project/templates, ~\symfony\Project\vendor\symfony\twig-bridge/Resources/views/Form).
Upvotes: 0
Views: 506
Reputation: 428
you should put your twig file in a subfolder of "templates" and call it "lucky" so the path to your twig template should be: templates/lucky/number.html.twig and not directly under templates
--templates
|
-- lucky
|
-- number.html.twig
Upvotes: 1