function parse($template, $outputFile = null, $append = false)
{
// main work done right here:
// hopefully this works recursively ... fingers crossed.
ob_start();
try {
$this->display($template);
} catch (Exception $e) {
ob_end_flush();
// flush the output on error (so we can see up to what point it parsed everything)
throw $e;
}
$output = ob_get_contents();
ob_end_clean();
if ($outputFile !== null) {
$outputFile = $this->resolvePath($outputFile, $this->outputDirectory);
$flags = null;
if ($append) {
$flags = FILE_APPEND;
}
if (!file_put_contents($outputFile, $output, $flags) && $output != "") {
throw new Exception("Unable to write output to " . $outputFile);
}
}
return $output;
}