Skip to content

Render Twig component from Twig extension #4538

Answered by GromNaN
michalschroeder asked this question in Q&A
Discussion options

You must be logged in to vote

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.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@michalschroeder
Comment options

Answer selected by michalschroeder
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #4537 on January 06, 2025 15:15.