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

template_from_string bug with "use" #877

Closed
syrm opened this issue Oct 31, 2012 · 8 comments
Closed

template_from_string bug with "use" #877

syrm opened this issue Oct 31, 2012 · 8 comments

Comments

@syrm
Copy link

syrm commented Oct 31, 2012

{% use template_from_string("{% block body %}Go{% endblock %}") %}

Fatal error: Uncaught exception 'Twig_Error_Syntax' with message 'The template references in a "use" statement must be a string in "event:dynamic" at line 3.' in /_vendor/TwigLibrary/lib/Twig/TokenParser/Use.php:41 Stack trace:
#0 /_vendor/TwigLibrary/lib/Twig/Parser.php(192): Twig_TokenParser_Use->parse(Object(Twig_Token))
#1 /_vendor/TwigLibrary/lib/Twig/Parser.php(100): Twig_Parser->subparse(NULL, false)

#2 /_vendor/TwigLibrary/lib/Twig/Environment.php(486): Twig_Parser->parse(Object(Twig_TokenStream))
#3 /_vendor/TwigLibrary/lib/Twig/Environment.php(536): Twig_Environment->parse(Object(Twig_TokenStream))
#4 /_vendor/TwigLibrary/lib/Twig/Environment.php(330): Twig_Environment->compileSource('{% extends "lay...', 'event:dynamic') # in /_vendor/TwigLibrary/lib/Twig/TokenParser/Use.php on line 41

@stof
Copy link
Member

stof commented Oct 31, 2012

{% use %} does not support dynamic templates (it cannot be a variable either, it has to be a string)

@syrm
Copy link
Author

syrm commented Oct 31, 2012

Hum ? Why not ?
The documentation said :
Even if you will probably always use the template_from_string function
with the include tag, you can use it with any tag or function that
takes a template as an argument (like the embed or extends tags).

@stof
Copy link
Member

stof commented Oct 31, 2012

But use does not take a template as argument. It takes a static template name. It cannot be dynamic. There is no dynamic use

@syrm
Copy link
Author

syrm commented Oct 31, 2012

The documentation said use take a template argument.

@stof
Copy link
Member

stof commented Oct 31, 2012

Here is the message I see in the doc of the use tag:

Because use statements are resolved independently of the context passed to the template,
the template reference cannot be an expression.

@syrm
Copy link
Author

syrm commented Oct 31, 2012

Ok, that's annoying.

@fabpot
Copy link
Contributor

fabpot commented Nov 1, 2012

closing. this might be possible in Twig 2.0 though.

@4d4ch4u32
Copy link

I'm using Twig 3.3 in Symfony 5.2.3, it's still not possible. :(

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

No branches or pull requests

4 participants