use output buffers to render a template (php)
Posted November 7, 2011on:
i have used the following as a way to render a template:
This way you can nicely separate out the logic from the outward presentation.
However, when we compose an email to send to the user, we would like use the same mechanism — have a template, and render it with a collection of variables.
After googling, i discover you can use output buffer to achieve the samething:
$html = ob_get_contents();
then you have a string of $html which contains an interpreted version of the template in question.
Easy to read, maintain, and refactor.