frameworks - Clean HTML output in ZF2 -


is possible fomat(clean) output of html in zend framework 2? right outputs without proper newline characters , tabs.

i know method:

$dom = new domdocument(); $dom->preservewhitespace = false; $dom->loadhtml($html); $dom->formatoutput = true; echo $dom->savehtml(); 

but not understand intercept output in zf2. appreciated.

right html code created in layout.

you can attach listener "finish" mvc-event ( http://framework.zend.com/manual/2.1/en/modules/zend.mvc.mvc-event.html ) , have clean response before sending out.

in application's module.php add following module class.

public function onbootstrap(mvcevent $e) {      $eventmanager = $e->getapplication()->geteventmanager();     $eventmanager->attach(mvcevent::event_finish, function(mvcevent $e){         $content = $e->getresponse()->getcontent();         $cleancontent = clean_up_html(content); // clean_up_html() not provided         $e->getresponse()->setcontent($cleancontent);     }); } 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -