I see lots of phtml files generated in var/view_preprocessed/html
, from core modules as well as from custom modules. It looks like these are all used templates with stripped whitespace.
Alan Kent wrote in How do I update Magento 2 phtml files in Grunt?:
You don't "deploy" PHTML files. They are referenced by blocks in layout files and processed on the server side. So "grunt" is not relevant here, and the static content deployment is similarly not relevant.
And when analyzing the static content deployment and grunt workflow I did not find anything related to templates, so I guess this still holds true.
But when are these files generated? And what is actually happening there and why?
Best Answer
When calling
bin/magento static-content:deploy
this gets called:\Magento\Deploy\Console\Command\DeployStaticContentCommand::execute()
This method calls
which translates to
\Magento\Deploy\Model\Deployer::deploy
. At the bottom of this method you will findIf you want you can dig deeper in
\Magento\Framework\App\Utility::getPhtmlFiles
to see how the templates are retrieved.Short version:
It calls
accumulateModuleTemplateFiles
andaccumulateThemeTemplateFiles
from the same class. These methods are using (in the end)glob
and some regular expressions to retrieve all the template files from the modules and from the themes and minifying is done by\Magento\Framework\View\Template\Html\Minifier
(that implements\Magento\Framework\View\Template\Html\MinifierInterface
) based on some strange regular expressions. (seeminify
method).The thing I don't know yet, it how are these templates loaded for use. most probably they are loaded by the template engine. I will post back here if/when I find that.
[EDIT]
I found when the minified templates are used. When you set the value for
Store->Configuration->Developer->Template Settings->Minify HTML
toYes
and when on production mode.