zendframework / zend-expressive

PSR-15 middleware in minutes!
BSD 3-Clause "New" or "Revised" License
711 stars 197 forks source link

Adding parameters to templates before render-time #142

Closed kynx closed 9 years ago

kynx commented 9 years ago

Right now we've only got one chance to add parameters to templates, via render($name, $params).

However it'd be really useful to add data in stages. So a piped middleware could be responsible for populating standard stuff like the current user's name, then the routed middleware adds the stuff it's responsible for.

Plates offers addData() that does just this. From what I can tell it's possible in Zend View as well. Twig doesn't, but it could be faked easily enough by storing the data in the Twig bridge until render time.

Anyone else think this is good idea?

akrabat commented 9 years ago

Twig has an addGlobal() method for this.

weierophinney commented 9 years ago

@akrabat - I missed that when we were updating the twig implementation. Could you maybe do a PR or open an issue against zend-expressive-twigrenderer to use that instead of the current approach? On Oct 11, 2015 6:07 AM, "Rob Allen" notifications@github.com wrote:

Twig has an addGlobal() method for this.

— Reply to this email directly or view it on GitHub https://github.com/zendframework/zend-expressive/issues/142#issuecomment-147182046 .

akrabat commented 9 years ago

Looking at how zend-expressive-zendview is implemented, I'd say that the way the Twig one is done is correct as this way we have per-template default parameters which isn't supported by Twig's addGlobal.

However, I don't see a way to add a parameter to every template as per the example in this issue?

akrabat commented 9 years ago

Ah - there's a weird template name called "TEMPLATE_ALL"… I would never have guessed that!

weierophinney commented 9 years ago

Evidently I need to make that more prominent in the docs... Any suggestions?

We could still have that proxy to twig's global, while providing the abstraction for per-template. Thoughts? On Oct 11, 2015 1:20 PM, "Rob Allen" notifications@github.com wrote:

Ah - there's a weird template name called "TEMPLATE_ALL"… I would never have guessed that!

— Reply to this email directly or view it on GitHub https://github.com/zendframework/zend-expressive/issues/142#issuecomment-147232682 .

weierophinney commented 9 years ago

Closed with #143