# Conditionally rendering a plugin outlet

**URL:** https://meta.discourse.org/t/conditionally-rendering-a-plugin-outlet/53838
**Category:** Development
**Created:** [December 6, 2016, 6:14am UTC](https://meta.discourse.org/t/conditionally-rendering-a-plugin-outlet/53838 "2016-12-06T06:14:50Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [December 6, 2016, 6:14am UTC](https://meta.discourse.org/t/conditionally-rendering-a-plugin-outlet/53838/1 "2016-12-06T06:14:50Z")

</div>

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.

 ![](https://global.discourse-cdn.com/meta/original/3X/2/5/25b4ea949c92a3f2e22395ac3722f417a28139e2.png)

I can easily add it by creating a plugin outlet in the UL per:

```plaintext
<ul>
   <li>...</li>
   {{plugin-outlet "users-stats" tagName="li"}}
</ul>

```

However

- I don’t want to display anything if the solution count is 0

- I need to push up a class `linked-stat` CSS class to the enclosing LI.

My suggestion:

We currently define the behavior in

```plaintext
discourse-solved/assets/javascript/discourse/connectors/users-stats/some_file.hbs

{{#link-to 'userActivity.solved'}}
  {{user-stat value=model.solved_count label="solved.solution_summary"}}
{{/link-to}}

```

I would like to add support for:

```plaintext
discourse-solved/assets/javascript/discourse/connectors/users-stats/some_file.js.es6

export default {
    shouldRender: function() {
        return this.get("model.solved_count") > 0;
    },
    classes: function() {
        return "linked-stat";
    }
};

```

@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.

Thoughts?

See also

[Allow registrations of components as plugin outlets](https://meta.discourse.org/t/allow-registrations-of-components-as-plugin-outlets/53464) which is a far heavier suggestion.

---

<div class="post-metadata">

### Author: ![vinothkannans](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vinothkannans/32/86465_2.png) [@vinothkannans](https://meta.discourse.org/u/vinothkannans)
#### Post date: [December 6, 2016, 7:29am UTC](https://meta.discourse.org/t/conditionally-rendering-a-plugin-outlet/53838/2 "2016-12-06T07:29:01Z")

</div>

I am also facing the same situation in many places. For example

> <https://github.com/vinkashq/discourse-branding/blob/master/assets/javascripts/discourse/templates/connectors/below-site-header/branding.hbs#L4>

Here I am displaying the banner only if all three conditions are passing.

---

<div class="post-metadata">

### Author: ![Mittineague](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mittineague/32/114259_2.png) [@Mittineague](https://meta.discourse.org/u/Mittineague)
#### Post date: [December 6, 2016, 7:43am UTC](https://meta.discourse.org/t/conditionally-rendering-a-plugin-outlet/53838/3 "2016-12-06T07:43:23Z")

</div>

Does Ember still support handlebar helper files?

I had a very alpha plugin I was working on that worked OK using a helper.

But after the switch to Virtual DOM I abandoned it and I don’t know if that might still be a way to approach the conditional rendering.

---

<div class="post-metadata">

### Author: ![eviltrout](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/eviltrout/32/5275_2.png) [@eviltrout](https://meta.discourse.org/u/eviltrout)
#### Post date: [December 6, 2016, 7:23pm UTC](https://meta.discourse.org/t/conditionally-rendering-a-plugin-outlet/53838/4 "2016-12-06T19:23:17Z")

</div>

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:

[https://github.com/discourse/discourse/commit/7b8e4a7110df1c40fa952df5fe216d844fbecc9d](https://github.com/discourse/discourse/commit/7b8e4a7110df1c40fa952df5fe216d844fbecc9d)

---

<div class="post-metadata">

### Author: ![eviltrout](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/eviltrout/32/5275_2.png) [@eviltrout](https://meta.discourse.org/u/eviltrout)
#### Post date: [December 12, 2016, 7:15pm UTC](https://meta.discourse.org/t/conditionally-rendering-a-plugin-outlet/53838/5 "2016-12-12T19:15:30Z")

</div>

There is now support for conditionally rendering a connector:

> [@Important changes to Plugin Outlets for Ember 2.10](https://meta.discourse.org/t/important-changes-to-plugin-outlets-for-ember-2-10/54136):
>
> Shortly I will be merging a branch of Discourse into master that updates us to the latest stable version of Ember, which is 2.10. This is exciting because we’ve been behind Ember’s stable branch for a while and we’ve finally caught up! It also contains the Glimmer 2 template engine which is quite a bit faster so the application should be more responsive, and it also cuts down on our template file sizes so the app should be quicker to download. However, there is a downside, and that I wasn’t abl…
