# Testing viewingSelf from plugin outlet

**URL:** https://meta.discourse.org/t/testing-viewingself-from-plugin-outlet/57576
**Category:** Development
**Created:** [2017年二月17日 21:57 UTC](https://meta.discourse.org/t/testing-viewingself-from-plugin-outlet/57576 "2017-02-17T21:57:09Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![LeoDavidson](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/leodavidson/32/119574_2.png) [@LeoDavidson](https://meta.discourse.org/u/LeoDavidson)
#### Post date: [2017年二月17日 21:57 UTC](https://meta.discourse.org/t/testing-viewingself-from-plugin-outlet/57576/1 "2017-02-17T21:57:10Z")

</div>

I’m using the `user-profile-primary` plugin outlet to add some things to the user pages.

In the .hbs template, I want some things to be conditional on whether the displayed user is the logged on user or someone else. This is done via a computed `viewingSelf` property in the internal templates, but it’s not available directly from the user model.

From [Important changes to Plugin Outlets for Ember 2.10](https://meta.discourse.org/t/important-changes-to-plugin-outlets-for-ember-2-10/54136) I can see that the child template no longer automatically inherits everything the parent template could use, and since viewingSelf is a computed property it looks like it is one of the missing things.

I also see in there that I can make a connector, and add whatever I need, so I’m trying something like this, just trying to get it so {{newTestThing}} will print the two usernames first:

```javascript
export default {
	setupComponent(args, component) {
		const modelUser = args.model.get("username");
		const activeUser = ???;
		component.set('newTestThing', modelUser + " --?-- " + activeUser);
	}
}

```

I can’t work out what should go into ??? though.

`currentUser`, `application`, etc. don’t seem to exist on `this` or on any of the objects contained in `args` (at least from trying various combinations, then setting a breakpoint and looking around in Chrome’s js debugger). **[EDIT: This statement is wrong. `this.currentUser` works fine. See a few posts down.]**

I’m probably missing something simple, but can’t see the wood for the trees at the moment. Any help much appreciated!

(I’m not tied to this method of doing things, either. If there’s an easier way to say `{{#if viewingSelf}}` inside the `user-profile-primary` outlet then that’s my real goal.)

---

<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: [2017年二月17日 22:12 UTC](https://meta.discourse.org/t/testing-viewingself-from-plugin-outlet/57576/2 "2017-02-17T22:12:59Z")

</div>

> [@LeoDavidson](#):
>
> don’t seem to exist on this

I thought for the most part a lot if the “main” objects had global scope, but you may need to pass the Discourse object to the function.

For currentUser try something like

```plaintext
var username = Discourse.User.currentProp('username') || "anon";

```

---

<div class="post-metadata">

### Author: ![LeoDavidson](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/leodavidson/32/119574_2.png) [@LeoDavidson](https://meta.discourse.org/u/LeoDavidson)
#### Post date: [2017年二月17日 22:19 UTC](https://meta.discourse.org/t/testing-viewingself-from-plugin-outlet/57576/3 "2017-02-17T22:19:42Z")

</div>

That did the trick. Many thanks for helping so quickly!

---

<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: [2017年二月27日 15:48 UTC](https://meta.discourse.org/t/testing-viewingself-from-plugin-outlet/57576/4 "2017-02-27T15:48:31Z")

</div>

I don’t recommend using the global objects. We are trying to phase those out because they are essentially global variables.

Instead you should be able to do something like:

```plaintext
const username = this.currentUser ? this.currentUser.get('username') : 'anon';

```

---

<div class="post-metadata">

### Author: ![LeoDavidson](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/leodavidson/32/119574_2.png) [@LeoDavidson](https://meta.discourse.org/u/LeoDavidson)
#### Post date: [2017年二月27日 16:43 UTC](https://meta.discourse.org/t/testing-viewingself-from-plugin-outlet/57576/5 "2017-02-27T16:43:27Z")

</div>

I can confirm that works, including in the file I was having problems with.

My statement that “this.currentUser” didn’t exist within the connector was wrong.

Looking again, I see where I went wrong: I was using Chrome’s debugger to see which properties/methods existed on the “this” object, but I didn’t realise it only shows some of them at the top level, with others nested inside the \__proto_\_ level. I’m still very much a javascript newbie and still getting surprised by differences vs my bread & butter C++.

Many thanks for your help!
