I was using the
vendor/bin/templatemap_generator.php to generate some of the module template mapping. But was wondering why we did it.
So the question that popped my mind was: how is Zend Framework finding the template file. So I started debugging to see what happend in the template resolvers. With the templatemaps it’s easy for the
Renderer to find the matching template as it’s in the
template_map key. And thus the first resolver returning the destination of the file is
What about without the template mapping. I removed the view name it was looking for from the
template_map.config.php to see what happend as it was no longer in the template configuration. The second resolver,
TemplatePathStack, will return the file.
Notice: using the default view structure as in
After a little debugging of the
Zend\View\Resolver\TemplatePathStack I saw it has paths of every module offering any view files. So it basically loops each and every path to see if the path of the model exists in any of these paths. The problem that I’ve with this is that if the module is one of the latest mentioned in the paths it has, it had to check each and every other path whether the file existed in it. While the path of the model is using a common format (convention) of
So is there a reason it is looping through each and every path, while we could find the path of the Module using the requested path of the viewModel, as in
We can only overwrite the paths of a view by redefining the key within the template map. It is not that one module is able to match anothers view path, using the format/convention.
When debugging I was using the following package version of
"zendframework/zend-view" : 2.9.0
Talking about the following file/line combination: