bcosca / fatfree

A powerful yet easy-to-use PHP micro-framework designed to help you build dynamic and robust Web applications - fast!
2.66k stars 446 forks source link

Remove HTML comments from template (minifying) #1274

Open Pique7 opened 10 months ago

Pique7 commented 10 months ago

Hello, What would be an appropriate method to remove HTML comments from my templates when they are rendered? I haven't found anything about it in the documentation.

I tried \Template::instance()->extend() but this does not work with HTML comments.

I also found View::afterrender() but I don't know whether might be helpful and how to utilize it. I am not that familiar with PHP and F3.

httpneo commented 10 months ago

Use the exclude Tags: <exclude><!-- HTML Comment --></exclude>

geniuswebtools commented 10 months ago

Here's the link to the documenation: https://fatfreeframework.com/3.8/views-and-templates#ExclusionofSegments

Pique7 commented 10 months ago

Oh, I really overlooked this in the documentation because I was focused on removing existing <!-- HTML comments -->. I think for my case the provided solution is acceptable. I can replace/complement all my comments with the <exclude> tag. Okay, thanks for your help!

pauljherring commented 10 months ago

Meanwhile, on the subject of minification, there is some functionality in core, but it's only for js and css:

Pique7 commented 10 months ago

Meanwhile, on the subject of minification, there is some functionality in core, but it's only for js and css:

* https://fatfreeframework.com/3.8/optimization#KeepingJavascriptandCSSonaHealthyDiet

* https://fatfreeframework.com/3.8/web#minify

Yes, initially I hoped this could be an answer to my problem but ironically my project barely contains custom CSS and JavaScript (yet). As already mentioned, for now the solution provided by @httpneo and @geniuswebtools seems to be suitable.

dabcorp commented 1 month ago

Hello use afterrender :

\Template::instance()->afterrender(function($html) { return Minify::MinifyHtml($html); });