Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

symfony 4 php template location

Please help, symfony 4 cant find php template.

The error is The template "::test/index.html.php" does not exist.

Controller :

namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;

class TestController extends Controller
{

    public function number()
    {
        $number = mt_rand(0, 100);

        // return new Response(
        //     '<html><body>Lucky number: '.$number.'</body></html>'
        // );
        return $this->render("test/number.html.php",
            array('number' => $number));
    }

    function index() {
        return $this->render("test/index.html.php");
    }
}

Directories:

  • templates/
    • test/
      • index.html.php
      • number.html.php

Thanks

like image 556
Superbiji Avatar asked Jan 01 '26 08:01

Superbiji


1 Answers

The shortcuts with the bundle:directory:filename notation is not used anymore in Symfony 4. Instead use real path's relative to the templates directory or for bundles use the syntax with the @ prefix. For more information: http://symfony.com/doc/current/templating.html#template-naming-and-locations

If your error occurs from a third party bundle then this bundle is not ready to work with Symfony 4. You could then fork the bundle and change the template notation in the controllers.

like image 89
Frank B Avatar answered Jan 03 '26 04:01

Frank B



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!