Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Adding parameters to templates before render-time #142

Closed
kynx opened this issue Sep 28, 2015 · 6 comments
Closed

Adding parameters to templates before render-time #142

kynx opened this issue Sep 28, 2015 · 6 comments

Comments

@kynx
Copy link
Contributor

kynx commented Sep 28, 2015

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
Copy link
Contributor

akrabat commented Oct 11, 2015

Twig has an addGlobal() method for this.

@weierophinney
Copy link
Member

@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
#142 (comment)
.

@akrabat
Copy link
Contributor

akrabat commented Oct 11, 2015

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
Copy link
Contributor

akrabat commented Oct 11, 2015

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

@weierophinney
Copy link
Member

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
#142 (comment)
.

@weierophinney
Copy link
Member

Closed with #143

weierophinney added a commit that referenced this issue Mar 14, 2017
Consistency in `composer serve` invocation. See
[zend-expressive-skeleton #142](https://github.com/organization/project/pull/142)
for details.
weierophinney added a commit that referenced this issue Mar 14, 2017
Consistency in `composer serve` invocation. See
[zend-expressive-skeleton #142](https://github.com/organization/project/pull/142)
for details.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants