Conditionally rendering a plugin outlet: sam proposes a mechanism for conditionally rendering outlets, starting with an unbound solution. They want to add a “solutions” tab to the summary page, but only if the solution count is greater than 0 and need to add a linked-stat CSS class to the enclosing LI.
sam suggests adding a shouldRender function to the outlet’s JavaScript file to achieve this. vinothkannans shares a similar use case, and Mittineague inquires about using Ember’s handlebar helper files for conditional rendering.
@eviltrout explains that implementing conditional rendering is challenging due to Ember’s stream-based dependencies and lack of access to the keyword’s scope. However, eviltrout later announces that support for conditionally rendering a connector is now available, as discussed in another thread.
I would like to introduce a mechanism for conditionally rendering outlets, I think for the time being even an unbound solution will go a reasonable distance.
The problem:
I am looking at adding a “solutions” tab to the summary page.
@eviltrout what are your thoughts on this, clearly getting full binding here is going to be much trickier, but for unbound decisions this seems pretty straight forward.
I spent a couple of hours on this and it’s unfortunately not easy either.
The plugin outlet is implemented as keyword that basically does the same thing as the partial tag in ember that hoists a block into the upper template, except I hoist a template we’ve declared as a connector.
Now of course I can conditionally do that, however it seems that I can’t access the scope of the keyword (or I can’t figure out how to anyway) because everything in ember is based on streams of dependencies that are passed into things.
There doesn’t seem to be any easy way in a keyword handler to call this.get('model.solved_count')
If you’re feeling adventurous and think you can figure out something in Ember’s API to do this, here’s my work: