Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blaze example of "Helper calculates which template to display, passing a data context to the template" doesn't actually work. #2123

Closed
tmeasday opened this issue May 7, 2014 · 9 comments

Comments

@tmeasday
Copy link
Contributor

tmeasday commented May 7, 2014

Number 2. from here: https://github.com/meteor/meteor/wiki/Using-Blaze#templatefoo-is-not-a-function-and-does-not-return-a-string

Reproduction: https://github.com/tmeasday/blaze-example-wrong

In Template.foo.post, this is set to the result of Template.foo.postData. You could work around this by setting Template.foo.postData = {foo: 'bar', postName: this.postName}.

Kind of crappy though, as most times postData would come from a collection.

@estark37
Copy link
Contributor

Hey @tmeasday -- excellent point, thanks! We're fixing this by replacing these examples with

{{> UI.dynamic template=foo data=bar}}

(where foo can be a helper that calculates the name of the template to display, and bar calculates the data context with which to render the subtemplate).

This will be on devel soon and out in the next release, at which point we'll update the wiki.

@philcockfield
Copy link

This looks great @estark37

@tmeasday
Copy link
Contributor Author

That seems like an ideal solution @estark37

@estark37
Copy link
Contributor

Glad to hear it -- @avital's idea :)

@mizzao
Copy link
Contributor

mizzao commented Jun 12, 2014

@estark37
Copy link
Contributor

{{> UI.dynamic}} is out in 0.8.2, and I've updated the wiki (though the wording is still in flux). Thanks @tmeasday!

@mizzao
Copy link
Contributor

mizzao commented Jul 14, 2014

I just spent half an hour figuring out that the helper passed in for the template argument requires "foo" rather than Template.foo. When using the latter, nothing at all is rendered. Especially confusing as {{> someTemplate}} where someTemplate is a helper expects Template.foo to be returned.

It would be great to make a note of this somewhere or maybe just support both depending on whether a string or a template component is passed in.

It also appears that UI._parentData(n) doesn't 'reach up' through UI.dynamic. Is it meant to be this way? I'm going to hop on devel for now and see if it's the same case with blaze-refactor.

@avital
Copy link
Contributor

avital commented Jul 23, 2014

Sure, we'll look at a pull request (with tests) letting UI.dynamic accept templates in addition to template names.

UI._parentData should do the exact same thing as ... So if you're right, I'd like to know whether .. behaves the right way or not. If you think there's a bug please file a new ticket.

@mizzao
Copy link
Contributor

mizzao commented Jul 25, 2014

Hi @avital, I discovered that this was actually due to a slightly different problem. See #2337.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants