How do you get the parsed HTML of a page on the back end? (Within an Extension Using PHP) EE5
2 Answers
I believe you use this extension hook:
Edit
Here is an example of how this could work. Set up your extension and register it to run this method on the hook:
public function my_template_post_parse_function($template, $is_partial, $site_id)
{
return str_replace("<my-tag>", "My-tag's output!", $template);
}
Read over the documentation on extension development for more information on how to use extensions and hooks:
https://docs.expressionengine.com/latest/development/extensions.html
-
How do I send the $this->final_template? Where does it come from? Example? Commented Dec 13, 2018 at 21:03
-
-
I must still be missing something. I have some learning to do. Commented Dec 17, 2018 at 17:28
Just in case someone else is looking for the answer: If after your extension is called you can rebuild the template using the following code
function your_function($obj){ $template_group = "template_group_name"; \\(string) $template = "template_name"; \\(string) ee()->uri->page_query_string = $obj->entry('entry_id');\\assign your own entry_id (int) ee()->load->library('template', NULL, 'TMPL'); ee()->TMPL->fetch_and_parse($template_group, $template, FALSE); $rendered = ee()->TMPL->parse_globals(ee()->TMPL->final_template); echo $rendered; }
Of course you can display it or set values how ever you want.