Skip to content
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

Add exist method to TemplateRendererInterface #58

Open
alexander-schranz opened this issue Nov 13, 2022 · 2 comments
Open

Add exist method to TemplateRendererInterface #58

alexander-schranz opened this issue Nov 13, 2022 · 2 comments
Labels
Feature A new feature to be added

Comments

@alexander-schranz
Copy link
Contributor

There are currently 2 options we can use. There can be a TemplateNotFoundException or a exist method on the TemplateRendererInterface. As feedback from @fabpot here: php-fig/fig-standards#1280 (comment):

Having to catch an exception for non-existing templates was a performance issue in Twig as we have a feature that let you fall back to other templates. So we added a way to check if a template exists that returns a Boolean.

So the exception isn't ideal and a exist method is better. We need to check which

@alexander-schranz alexander-schranz added the Feature A new feature to be added label Nov 13, 2022
@stof
Copy link

stof commented Nov 15, 2022

Another note: an exception does not allow to implement the fallback feature if the only API you have is ->render(), as you don't want the fallback to apply if the template exists but include another template for which we have a failure (with no fallback there). Twig used to be able to use an exception-based logic for that thanks to its loadTemplate API that only loads (and compiles) a template without rendering it (and so without resolving other imports which might trigger the exception as well). Without that, you don't know whether the exception is for your own template or a referenced one.

@alexander-schranz
Copy link
Contributor Author

@stof that is great insight knowledge about the handling. Thank you for sharing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature A new feature to be added
Projects
None yet
Development

No branches or pull requests

2 participants