Hello all,
Little stuck on how to override what a field outputs when being called within a template file.
Take the following sample code inside a template:
<h1>
<?=$page->title?>
</h1>
<div>
<?=$page->another_field?>
</div>
What I'm trying to do is analyse and potentially modifying the output of this field from within a template, using a module WITHOUT saving the page.
This is currently the code that I'm trying to run
public function init() {
// add a hook after each page is rendered and modify the output
$this->addHookBefore('Page::render', $this, 'exec');
}
public function exec($event) {
//Get the rendered page
$page = &$event->object;
if($page->template == 'admin') {
return;
}
//As a test, try and modify the title field, but in the future I'll need to be able to modify any fields
$page->set("title","A test title!");
}
Unfortunately, this doesn't work. - The page still renders the original title within the template!
Ideally - my long term goal is to know:
What the field type of the called/rendered field is The current value of this field
Any guidance is appreciated!