Skip to content

[Templating] TemplateReference::getPath hardcodes "views" directory #25019

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
geecu opened this issue Nov 18, 2017 · 5 comments
Closed

[Templating] TemplateReference::getPath hardcodes "views" directory #25019

geecu opened this issue Nov 18, 2017 · 5 comments

Comments

@geecu
Copy link

geecu commented Nov 18, 2017

Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? yes/no
Symfony version 3.4.0-BETA2

While trying to add Symfony 4 support to LiipThemeBundle I came across this: the bundle calls Symfony\Bundle\FrameworkBundle\Templating\Template\TemplateNameParser::parse() with a simple name (not containing a bundle): index.html. This creates a TemplateReference with no bundle, but TemplateReference::getPath() returns views/index.html.twig for the path. As with the twig engine the templates is searched in templates/ directory, this looks like a bug.

@nicolas-grekas
Copy link
Member

@yceruto would you mind checking this one please?

@yceruto
Copy link
Member

yceruto commented Nov 20, 2017

It looks like you're rendering a template that does not exists in Twig paths (run debug:twig to list the "Loader Paths") or it is loading like ::index.html.twig and as far as I can see (after Twig LoaderError) the templating BC layer rely on the kernel file_locator only, which just contains src/ and src/Resources/ paths, so if you have this template in src/Resources/views/ it works!

IMHO, nothing to do here ;) because the templating layer is absolete and it keep only BC with old structure.

@geecu
Copy link
Author

geecu commented Nov 21, 2017

I've created two Symfony 3.4 projects. In both of them I required the server package, so you can run ./bin/console server:run.

In this project:
https://github.com/geecu/sf34-twig
I required the twig package, uncommented the routes in config/routes.yml, added a DefaultController with an index method that calls $this->render('index.html.twig'). This renders the template in __PROJECT_ROOT__/templates/index.html.twig.

In this project:
https://github.com/geecu/sf34-templating
I required the templating package, uncommented the routes in config/routes.yml, and added

framework:
  templating:
    engines: ['php']

This has a default controller that calls $this->render('index.php');. I was expecting this to work similar to the twig and render the file __PROJECT_ROOT__/templates/index.php.

But if you say it's kept only for BC and this is not to be expected, it's fine with me, I can close this issue.

While at it, I tried adding the src/Resources/views/index.php file. This renders the contents of that file, but it also throws:

The autoloader expected class "App\Resources\views\index" to be defined in file "__PROJECT__/vendor/composer/../../src/Resources/views/index.php". The file was found but the class was not in it, the class name or namespace probably has a typo.

@yceruto
Copy link
Member

yceruto commented Nov 21, 2017

Try renaming the template to src/Resources/views/index.html.php? and yeah, AFAIK symfony/templating component as template engine is obsolete.

@geecu
Copy link
Author

geecu commented Nov 21, 2017

It works. Closing this issue as, per your mention, the templating component is obsolete. As far as I understand, the twig bridge doesn't work with the templating component, it has a separate implementation...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants