ZF-Commons / ZfcTwig

Zend Framework 2 Module that provides a Twig rendering strategy
BSD 3-Clause "New" or "Revised" License
96 stars 55 forks source link

Add ViewModel::addChild(...) support #87

Open pmattmann opened 10 years ago

pmattmann commented 10 years ago

At the moment, ZfcTwig does not support TreeRendering.

Is there a good reason for this? What is the Twig-Way to handle ViewModel-Trees?

I tried to check the current implementation and I think I have detected the main problem. In the class Zend\Mvc\View\Http\InjectViewModelListener Zend builds usually a mini-tree where the controller response gets wrapped with the layout. This is not helpful, as Twig handles layouts by deriving templates.

I see different ways to handle this problem and so to add support for TreeRendering:

After implementing one of these 3 ideas, one could then change the TwigRenderer to not return in the foreach loop over all children, but one could then call the rendering-method recursively and store the rendering result in the $values of the parent ViewModel.

Personally, I would prefer the second idea. I expect that idea to be the most forward compatible of all of them.

What do you think? Would you accept a pull request going in that direction?

Regards, Pirmin

PS. Sorry for the poor english - i hope, you get the idea...

spiffyjr commented 10 years ago

I tried to handle this and actually attempted it in a few of the methods you presented and the issue is providing proper support for both phtml (used in modules) and twig files without breaking one or the other. If you can submit a PR that clearly defines what you're trying to accomplish as well as an example/use-case that would help.