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
Post a Comment