0

My controller is /src/AppBundle/Controller/TestsController.php and the class is:

class TestsController extends Controller
{
    /**
     * @Route("/tests/index", name="testsIndex")
     */
    public function indexAction(Request $request)
    {
        return $this->render('AppBundle::tests\index.html.twig', [
            'text' => "Hello world"
        ]);
    }
}

My view is /src/AppBundle/Resources/views/tests/index.html.twig and contains:

{{text}}

But when I try to open http://localhost/project/web/tests/index the error shows:

Unable to find template "AppBundle::tests/index.html.twig" (looked into: D:\www\project\app/Resources/views, D:\www\project\vendor\symfony\symfony\src\Symfony\Bridge\Twig/Resources/views/Form).

I followed this thread which error is pretty much the same but still can't find the mistake. It's driving me nuts.

Unable to find template in Symfony 3

Thanks!

Rajo
  • 71
  • 10
  • 1
    One colon after the AppBundle is all you need but that syntax is going away. Use @App/tests/index.html.twig https://symfony.com/doc/3.4/templating.html#referencing-templates-in-a-bundle – Cerad Jul 14 '18 at 22:44
  • 1
    See the [accepted answer here](https://stackoverflow.com/questions/47832977/symfony-3-4-use-view-inside-my-bundle/47835716#47835716) if you want to know why the old format does not work and what is needed to enable it. But again, just use the twig namespace @ format. – Cerad Jul 14 '18 at 22:56
  • A thousand thanks to you, @App/tests/index.html.twig worked like a charm! – Rajo Jul 14 '18 at 23:36

3 Answers3

1

Should work, but try AppBundle:tests:index.html.twig.

You might also want to use uppercase Tests instead of tests. More conventional.

Padam87
  • 1,013
  • 1
  • 6
  • 7
  • Yeah, kind of thought so... try what Cerad suggested. If that still does not work please post your structure. Is AppBundle your namespace root? – Padam87 Jul 14 '18 at 23:02
0

Cerad's solution was perfectly right:

@App/tests/index.html.twig
Rajo
  • 71
  • 10
0
/**
 * @Route("/tests/index", name="testsIndex")
 */
public function indexAction(Request $request)
{
    return $this->render('tests\index.html.twig', [
        'text' => "Hello world"
    ]);
}

This should work.

Dirk J. Faber
  • 4,360
  • 5
  • 20
  • 58