0

I need to view the HTML generated by Drupal and it is pretty hard. If I want to the final output to be put through an HTML beautifier before sending it off to the client where would I do that?

I am sure some of the page optimization utilities on the admin/config/development/performance or the advagg module are at the right place in the pipeline. What stage or APIs would I have to hook into to accomplish something this?

Are there any APIs which can be hooked into to accomplish this or even modules to this?

1 Answer 1

1

Yes, in advagg is a good example, you have to get the response content with $response->getContent() in a response subscriber http://cgit.drupalcode.org/advagg/tree/src/EventSubscriber/ResponseSubscriber.php?h=8.x-3.x

  public function onResponse(FilterResponseEvent $event) {
    // Only care about HTML responses.
    if (stripos($event->getResponse()->headers->get('Content-Type'), 'text/html') === FALSE) {
      return;
    }

    $response = $event->getResponse();
    $html_markup = $response->getContent();
    // modify html markup
    $response->setContent($html_markup);
  }
2
  • What is the appropriate stage in Drupal 7?
    – vfclists
    Jul 4, 2017 at 7:18
  • I see you've added a new tag for D7, don't know anything about this, but you can try to look in the D7 code of advagg
    – 4uk4
    Jul 4, 2017 at 7:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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