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

Render Helper cannot accept dynamic property as its first parameter, though the Partial Helper can? #9545

Closed
SimonKaluza opened this issue Nov 12, 2014 · 11 comments
Labels

Comments

@SimonKaluza
Copy link

Can I pass in a dynamic template name to a render call in Handlebars for Ember.js?

I'm attempting to create a component (a filter table) that accepts a run-time property that specifies exactly what template to render while looping over a collection of objects. My code works fine when using the partial helper to leverage a dynamic property parameter for the first parameter passing in a a bodyTemplate property on the parent component like:

{{#each r in records}}
  <tr>
  {{partial bodyTemplate}}
  </tr>
{{/each}}

but fails when I use the render helper call in the same way like:

{{#each r in records}}
  <tr>
  {{render bodyTemplate r}}
  </tr>
{{/each}}

The error that gets logged to the console is:

Uncaught Error: Assertion Failed: You used `{{render 'bodyTemplate'}}`, but 'bodyTemplate' can not be found as either a template or a view.

Though this seems to be a separate issue from the inability to set up controller bindings in render helper calls like #1914 describes, but are these two issues related? I intend to debug look into this further, but I wanted to see if anyone had some initial feedback.

@rwjblue rwjblue closed this as completed Nov 12, 2014
@rwjblue rwjblue reopened this Nov 12, 2014
@rwjblue
Copy link
Member

rwjblue commented Nov 12, 2014

Whoops. Sorry about that.

@jasonmit
Copy link
Member

This was likely never implemented into the render helper, though I would consider it a bug for being inconsistent with view and partial helpers.

To hopefully unblock you until this is fixed, you can likely accomplish what it is you're trying to do using just the view helper. If you need these objects backed by specific itemControllers, that can also be done by enumerating over an ArrayController and overriding lookupItemController.

http://jsfiddle.net/NQKvy/1495/

Edit: Updated to reflect the lookupItemController approach

@SimonKaluza
Copy link
Author

Ahh yes @jasonmit, that works very nicely! Thanks for that detailed jsfiddle example.

@givanse
Copy link

givanse commented Nov 24, 2014

@jasonmit Yeah, I find it strange too. Caught me of guard and I actually thought that I was doing something wrong untill I found both Github issues.

@rwjblue
Copy link
Member

rwjblue commented Jan 5, 2015

Sorry for taking so long on a response here, but I'm going to close this now...

{{render}} will be deprecated in 2.0, so I do not think we will be changing the way this works in the interim.

@rwjblue rwjblue closed this as completed Jan 5, 2015
@petermumford
Copy link

@rwjblue if your deprecating {{render}} in Ember 2.0 what should we start using instead and what are the reasons? I find the {{render}} helper really useful. It's just a real shame we can't use the first property as a dynamic property.

@jbrown
Copy link
Contributor

jbrown commented Feb 10, 2015

@petermumford Is #10093 not a suitable replacement?

@jasonmit
Copy link
Member

@petermumford if controllers are going away naturally this would go away. I am guessing, the recently merged component helper would be its replacement.

@petermumford
Copy link

@jbrown @jasonmit Thanks for pointing me to this, I really like the way it can swap components form a dynamic property, very useful. I'll need to revise what I've currently got as I'm using the {{render}} controller for data but no biggie.

@luxzeitlos
Copy link
Contributor

@jbrown well, components have side effects, you can not use the same from a route then inside a template with {{render}}.
Also, and more important, a controller is more isolated. So for example no access to the store.

@wagenet
Copy link
Member

wagenet commented Feb 28, 2015

@Krutius I'm not sure what you mean by components having side effects. I also don't understand your comment about controllers being more isolated. See also emberjs/rfcs#38 for future direction.

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

No branches or pull requests

8 participants