2

How do you get the parsed HTML of a page on the back end? (Within an Extension Using PHP) EE5

1

I believe you use this extension hook:

https://docs.expressionengine.com/latest/development/extension_hooks/global/template/index.html#template-post-parse

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

3
  • How do I send the $this->final_template? Where does it come from? Example? Dec 13 '18 at 21:03
  • I added a simple example.
    – jrothafer
    Dec 14 '18 at 0:39
  • I must still be missing something. I have some learning to do. Dec 17 '18 at 17:28
1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.