1
votes

You can not use the "render" method if the Templating Component or the Twig Bundle are not available. Try running "composer require symfony/twig-bundle".

class RecordsController extends AbstractController
{
    /**
     * @Route("/", name="single_page")
     * @return Response
     */
    public function singlePageAction()
    {
        return $this->render('single_page.html.twig', []);
    }
}

Symfony 4 - Not rendering Twig Template

Same as for this guy but accepted answer does not help.

Tried also

composer require debug --dev

then got error

[InvalidArgumentException]
Could not find package debug.

Did you mean one of these?
symfony/debug
tracy/tracy
maximebf/debugbar
cakephp/debug_kit
symfony/debug-pack

so installed symfony/debug. Which does not make any sense but I did. Of course it did not fix the problem.

Here is how composer.json now looks:

{
    "require": {
        "symfony/maker-bundle": "^1.13",
        "twig/twig": "~2.10",
        "symfony/twig-bundle": "^4.3"
    },
    "require-dev": {
        "symfony/debug": "^4.3"
    }
}

I have installed twig 2 because otherwise could not install twig-bundle - was gettig error.

How to get rid of this error and show the template?

Update: Noticed that my application has 2 composer.json files. One in root, another in myapp folder. Guess this is why after install it does not see because it is installed in that root directory. But now I am too angry and tired already to check, will need to do that later.

1

1 Answers

0
votes

in order to use twig, after installing the package with composer, you should enable the bundle for your environment(s). Here you have the docs for the current version of symfony https://symfony.com/doc/current/bundles.html

Once you do that, you have to inject twig in your AbstractController.

If you already did all of these steps, I suggest you to add some more code, in order to allow the community to spot the problem.

I also suggest you to avoid using multiple composer.json files: use just one in your project root directory.

Goodbye!