I need to do a search and replace on template files before I render them (This is a very special use case that I've ran into).
I noticed the afterrender but no beforerender. So I wrote some code outside the framework just before I render the template.
if ($f3->MIME == "text/html")
{
if (!cache::instance()->exists(base::instance()->hash($f3->FILE))) {
$contents = file_get_contents(getcwd()."/".$f3->FILE);
$contents = preg_replace_callback("/<ckeditor>/", function ($match) {
$id = substr("cid-".md5(uniqid(rand(), true)), 0, 12);
return '<ckeditor id="'.$id.'">';
}, $contents);
file_put_contents(getcwd()."/".$f3->FILE, $contents);
}
}
Ignore the two globals MIME and FILE. Those are my own.
The biggest problem with this is that it doesn't apply for inner templates.
So my next step is to add code into view class to accomplish this.
Before I go hurderling in I'd just like to double check that it would be best to add beforerender. I'll do a PR but up to Bong or Ikkez to accept it if they feel its a proper addition to the framework.