1

I'm having some trouble runnning Symfony. In fact, it can't find the default twig template. I didn't touch the code at all, juste generated my bundle and trying to access /web/app_dev.php.

My template is in

/src/OC/PlatformBundle/Resources/views/Default/index.html.twig.

Symfony looked into these locations, but not where my template actually is.

/app/Resources/views
/vendor/symfony/symfony/src/Symfony/Bridge/Twig/Resources/views/Form

And the DefaultController.php indexAction() looks ok :

public function indexAction(){
    return $this->render("OCPlatform:Default:index.html.twig");
}

If any of you have ever faced this kind of issue or have any idea where the problem comes from, I thank you in advance for your help.

Arthur

Arthur Klipfel
  • 71
  • 1
  • 10
  • 1
    Assuming you are using S3.4 or 4.0 then probably a dup of: https://stackoverflow.com/questions/47832977/symfony-3-4-use-view-inside-my-bundle/47835716#47835716 – Cerad Dec 21 '17 at 22:24

6 Answers6

2

I've same problem and i resolve it with this route :

public function indexAction(){
    return $this->render("@OCPlatform/Default/index.html.twig");
}

Edit ":" with "/" and it work. Maybe can help other developper

  • 1
    Add an other information. Don't write "bundle". Exemple : Use that. `return $this->render("@OCPlatform/Default/index.html.twig");` And no : `return $this->render("@OCPlatformBundle/Default/index.html.twig");` – Julien BOCK Jun 04 '18 at 12:15
1

If you want to keep using the 'OCPlatform:Default:index.html.twig' format for templates then edit your app/config/config.yml file:

#app/config/config.yml
framework:
    templating:
        engines: ['twig']

This fixed my problem. You can check this link Symfony 3.4 Use view inside my bundle

Solomon Tesfaye
  • 186
  • 2
  • 10
0

Following the docs(Symfony >=3.4) you should write the path to the template in the controller like this:

public function indexAction(){
    return $this->render("@OCPlatform:Default:index.html.twig");
}
Chris
  • 799
  • 6
  • 15
0

This worked for me:

return $this->render('@HomeBundle/Default/index.html.twig');


Hope it hope :)

fudu
  • 617
  • 1
  • 10
  • 19
0

Referencing Templates in a Bundle¶

If you need to refer to a template that lives in a bundle, Symfony uses the
Twig namespaced syntax (@BundleName/directory/filename.html.twig).
This allows for several types of templates, each which lives in a specific location:

@AcmeBlog/Blog/index.html.twig: <br>This syntax is used to specify a template for a specific page. The three parts of the string, each separated by a slash (/), mean the following:<br>
    @AcmeBlog: is the bundle name without the Bundle suffix. This template lives in the AcmeBlogBundle (e.g. src/Acme/BlogBundle);<br>
    Blog: (directory) indicates that the template lives inside the Blog subdirectory of Resources/views/;<br>
    index.html.twig: (filename) the actual name of the file is index.html.twig.
Otobong Jerome
  • 401
  • 6
  • 5
0

In symfony 4 use this :

    return $this->render("@Platform/Default/index.html.twig");
saeed
  • 79
  • 5