I want to use plates as template engine, but would like to use zend-form view helpers for rendering the form, maybe zend-navigation view helpers as well.
Is it possible to integrate zend-view-helpers (e.g. for rendering a form) into the plates template engine in a simple way?
Or, do I have to create a plates extension for each and every view helper, I want to use?
I would appreciate it much if someone could direct me to tutorials or extensive documentation on plates!
thanks again for Your reply.
I don’t really understand what’s happening inside ZfcTwig because I am not familiar with ZfcTwig.
Maybe You can point me to the essential parts.
In ZfcTwig\View\TwigRenderer I find the methods __call() and plugin(). I guess the important things happen here. The rest seems to be Twig related stuff.
In short, what I want to do, is use zend-expressive and use plates for the view part, but be able to use the zend-view helpers such as pagination, navigation, forms inside plates.
My idea based on Your proposal is to extend zend-expressive-platesrenderer.
I guess, I have to create a new Zend\View\HelperPluginManager or at least a factory for it and modify the Zend\Expressive\Plates\PlatesRenderer(Factory) (or the PlatesEngine) such that it does what You proposed in Your reply.
Is that the right direction?
Is that, what You meant in Your reply?
Thanks in advance and sorry for my stupidity (still learning),
I have used plates in a project, but I haven’t tried to add zend-view plugins to it. I don’t know if this can be done directly without creating an extension that would act between plates and the zend-view plugins.
A plates extension can be really basic. Have a look at how it’s done for zend-escape:
I guess you can create one custom zend-view-plugin extension like that and register the plugins you need the same way as in that escape plugin.
That would mean something like either a very big extension which takes into account each and every needed zend-view-helper or an extra extension for each zend-view-helper.
I was looking for a more elegant way.
You said that You have already used plates in different projects so far.
How do You deal with navigation, form, pagination etc.?
Do You use plain html in the templates/partials?
For forms I use html. As long as the forms are not too complicated I find this a lot faster than using zend-form. And for pagination I use a partial to which I pass some basic info and it creates the html. For the top bar navigation I also use plain html. As I don’t need dynamically created routes, it’s good enough for me. But if applications get more complex I need to start looking at those components as well.
You are right.
Only when using the installer, but the installer has defaults as well!
It seems, it was zend-view instead of plates (at least, it was in version 0.4 of zend-expressive-skeleton) - see outdated image below.
It is “nothing” in release-3.0.
I remember it was plates someday, nevertheless!
I think the default was always no template engine. As you can see in that image, the default there is (n) or none of the above. Option 3 was chosen in that image.
But I think plates was recommended in the docs though as it is fast and lightweight. However if you use Twig with caching enabled it’s also really fast.
N.B. Zend\View\HelperPluginManager is registered for you if you’ve installed via the skeleton.
Then In your Action Factory:
$helpers = $container->get(HelperPluginManager::class);
$zvphprenderer = new PhpRenderer;
Then In your Action, having passed in $zvphprenderer:
$data['zendviewphprenderer'] = $this->zvphprenderer;
//render Plates view (assuming Plates is your default template)
return new HtmlResponse(
In your Plates view template you can now make use of various Zend View Helpers
<?php $pl = $zendviewphprenderer->placeholder('foo')->set('some random text');?>
<?php echo $zendviewphprenderer->placeholder('foo'); ?>
Regarding zend-form view helpers, you will of course need zend-form installed. The cookbook
documentation at https://docs.zendframework.com/zend-expressive/cookbook/using-zend-form-view-helpers/
instructs to use the Zend Form ConfigProvider by adding a zend.form.global.php to
config/autoload directory (may be set up automatically on install?), replacing
HelperPluginManagerFactory and changing the entry for it in config/autoload/templates.global.php
However I have found zend form view helpers work without replacing
HelperPluginManagerFactory (Zend\Expressive\ZendView\HelperPluginManagerFactory) which seems to do the job, as the zend form config provider (zendframework/zend-form/src/ConfigProvider.php)
returns the form view helpers with a view_helpers key which
HelperPluginManagerFactory already checks for to configure the service manager.
Going down the delegator factory route (may not be necesary):