Template resolver allows to override templates, e.g. to override e-shop templates in project bundles. It is another way how to override templates beside the default Symfony overriding functionality (http://symfony.com/doc/current/book/templating.html#overriding-bundle-templates).
Moreover, a web-site redesign is an another case when template resolver could come useful.
The idea behind the template resolver came from old eZ Publish 4 times, when it was possible to override any template using design combinations.
Template resolver sequentially goes through all configured bundles and designs (if specified), looking for the requested template. At last, if the requested template still hasn't been found, template resolver takes this template or default one if the requested template doesn't exist.
An override is activated by a template resolver configuration. You can configure:
Let's say you have a project with a bundle src/Client/Bundle/WebsiteBundle, a site access website_de_de and you want to override eZ Commerce bundle templates.
Template resolver is deactivated in the default configuration and has to be activated!
Template resolver uses dynamic configuration of eZ Publish config resolver.
If you wand to have one configuration for all site accesses, change site access name to "default". E.g.:
In order to override templates you have to reflect a structure of eZ Commerce vendor bundles, e.g.:
In this example the template from ClientWebsiteBundle overrides catalog.html.twig from SilversolutionsEshopBundle.
Next, you can create more and more templates using the folder structure of eZ Commerce bundle.
Design is just an additional folder in your Resources/views. Templates in the design folder have to reflect a structure of the bundle or bundles that you want to override.
Assume that you are preparing templates for a website redesign with a provisional name "redesign2015".
Create new folder Resources/views/designs/redesign2015 in your bundle and put new templates there:
In this example the template from the desing "redesign2015" in the ClientWebsiteBundle overrides catalog.html.twig from SilversolutionsEshopBundle.
Templates in design folders always have precedence over other templates.
If you have both redesign2015/Catalog/catalog.html.twig and Catalog/catalog.html.twig, the first one will win.
|siso_tools.<scope>.template_resolver.enabled||bool (true|false)||Enable or disable template resolver||true||true|
|siso_tools.<scope>.template_resolver.bundles||array||List of bundle names||[ ] (all bundles)||[Bundle1, Bundle2, Bundle3]|
|siso_tools.<scope>.template_resolver.designs||array||List of bundle names||[ ] (none)||[Design1, Design2]|
|siso_tools.<scope>.template_resolver.default_template||string||Default template to return if nothing is found||SisoToolsBundle:TemplateResolver:default.html.twig||SisoToolsBundle:TemplateResolver:default.html.twig|
To make a template overridable, you have to use a template filter st_resolve_template with its name.
It is not possible to include blocks with "use" tag because of specific implementation of this tag.
To make using of TemplateResolver in controllers easier, you can inherit your controller from Silversolutions\Bundle\EshopBundle\Controller\BaseController. In this case render and renderView method will get rendered template using TemplateResolver, i.e. overriden template.
Alternatively, you can inject TemplateResolver in your service (or take it from container) and resolve template there
You can information about TemplateResolver configuration and overridden templates in the SilverSolutions tab of symfony web provider.
it is not possible to use the template resolver in the configuration, therefore for overriding standard templates for e.g. full eZ template or templates defined for eZ flow, you need to override the configuration