XF 2.0 How to manipulate template code before saving as file?

mjda

Well-known member
In XF1 I modified the code in /library/XenForo/Template/FileHandler.php -> save() but I'm having trouble figuring out how to do the same thing in XF2. Can anyone point me in the right direction?
 
The closest equivalent there would be XF\Service\Template\Compile::writeCompiled().

Just out of curiosity, why do you want/need to modify the compiled output?
 
The closest equivalent there would be XF\Service\Template\Compile::writeCompiled().

Just out of curiosity, why do you want/need to modify the compiled output?

Thanks! I'll give it a look.

I read that I could save small amounts of data per page view, and slightly increase page loading speeds, by minifying the html. Modifying that output was the only way I found to accomplish that.
 
I'm not sure if modifying the compiled templates would be the way to do that since they contain a lot of PHP within them (would definitely make any php errors that come from templates for whatever reason much more painful to debug as well). Might be easier to minify the rendered output before serving it, I wouldn't think that there would be any sort of noticeable performance implication to doing it then, but I haven't tried it.
 
Yeah that makes me feel a bit uneasy.

As Jake says, modifying the final output HTML is probably the best bet. The best target for that (if you want a quick and dirty way of modifying the HTML) is XF\Pub\App::renderPageHtml().
 
I'm not sure if modifying the compiled templates would be the way to do that since they contain a lot of PHP within them (would definitely make any php errors that come from templates for whatever reason much more painful to debug as well). Might be easier to minify the rendered output before serving it, I wouldn't think that there would be any sort of noticeable performance implication to doing it then, but I haven't tried it.

I would imagine that would just increase the server response time and I certainly don't want to do that. I don't do much extreme modifying. It's really just getting rid of a lot of the unnecessary white space characters. I was able to knock out at least 1-2Kb per page view. It's not much, I know, but I haven't had any problems with it running on my site and I like how much neater it makes the page source look. Yes, I'm extremely OCD. Ha!
 
Top Bottom