I would like to integrate an Templating Engine (TWIG) within our custom plugin.

My question is: how to handle/pass parameters which already are "echoing" its content. for example:

echo $this->twig->render($file, ['val1' =>  settings_fields('settings')]; 
  • This is probably a question best posed to Twig's support channels
    – bosco
    Apr 28, 2022 at 7:15

1 Answer 1


I would use output buffering to capture the content, then pass that in to the template.

$settings_fields = ob_get_clean();
echo $this->twig->render($file, ['val1' =>  $settings_fields]);

I think that should work.

  • That is the approach, which I had used in our custom Template Engine. I thought there is more adequate way to handle it without the the output buffering functions.. nevertheless Thank you for your answer Apr 21, 2022 at 9:33

Not the answer you're looking for? Browse other questions tagged or ask your own question.