Render Twig component from Twig extension #4538
Answered
by
GromNaN
michalschroeder
asked this question in
Q&A
-
Beta Was this translation helpful? Give feedback.
Answered by
GromNaN
Jan 6, 2025
Replies: 1 comment 1 reply
-
The first solution will require a runtime compilation of the template, which should be avoided if possible. Also, streaming would be preferred. public function test(\Twig\Environment $env): iterable
{
yield from $env->createTemplate($html)->stream();
}
} But the 2nd option is better, as you avoid a layer of Twig template. However, the best solution may be to use a macro or an include to keep everything in Twig. |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
michalschroeder
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The first solution will require a runtime compilation of the template, which should be avoided if possible. Also, streaming would be preferred.
But the 2nd option is better, as you avoid a layer of Twig template.
However, the best solution may be to use a macro or an include to keep everything in Twig.