# \[IGN-6563\]How to get view name inside the view itself

**URL:** <https://forum.inductiveautomation.com/t/ign-6563-how-to-get-view-name-inside-the-view-itself/63819>\
**Category:** Ignition Early Access\
**Created:** [September 7, 2022, 4:43am UTC](https://forum.inductiveautomation.com/t/ign-6563-how-to-get-view-name-inside-the-view-itself/63819 "2022-09-07T04:43:29Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![nader.chinichian](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nader.chinichian/32/9261_2.png) [@nader.chinichian](https://forum.inductiveautomation.com/u/nader.chinichian)\
**Post date:** [September 7, 2022, 4:43am UTC](https://forum.inductiveautomation.com/t/ign-6563-how-to-get-view-name-inside-the-view-itself/63819/1 "2022-09-07T04:43:29Z")

</div>

Is there any way to get the view name inside the view itself?  
I can’t use page.props.primaryView because I mostly use an embedded view.

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [September 7, 2022, 4:57am UTC](https://forum.inductiveautomation.com/t/ign-6563-how-to-get-view-name-inside-the-view-itself/63819/2 "2022-09-07T04:57:05Z")

</div>

Call the prop.path property of the embedded view component, and it should produce the name:

**Example:**  
` ./EmbeddedView.props.path`  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/9/2941b32dfc9c0004a3799995e1fc5faeeffb54ea.png)

**The preceding binding on a custom property produces the following result:**  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/8/e8c7c66b0c58c156404b5e691813a4bdd790799a.png)

---

<div class="post-metadata">

**Author:** ![nader.chinichian](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nader.chinichian/32/9261_2.png) [@nader.chinichian](https://forum.inductiveautomation.com/u/nader.chinichian)\
**Post date:** [September 7, 2022, 5:32am UTC](https://forum.inductiveautomation.com/t/ign-6563-how-to-get-view-name-inside-the-view-itself/63819/3 "2022-09-07T05:32:38Z")

</div>

> [@justinedwards.jle](#):
>
> ./EmbeddedView.props.path

Not working you are inside the view itself. "EmbeddedView" is unknown and even works it may change by user.

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [September 7, 2022, 5:47am UTC](https://forum.inductiveautomation.com/t/ign-6563-how-to-get-view-name-inside-the-view-itself/63819/4 "2022-09-07T05:47:13Z")

</div>

Have you tried `self.page.props.pageId` ?

Edit:  
From within a property binding, it would just be: `page.props.pageId`

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [September 7, 2022, 6:38am UTC](https://forum.inductiveautomation.com/t/ign-6563-how-to-get-view-name-inside-the-view-itself/63819/5 "2022-09-07T06:38:43Z")

</div>

I see what you are saying. When the view is embedded, the parent view and sub-view become indistinguishable:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/1/71d779a5e29eb71ad065c032ec75027771339d32.png)

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [September 7, 2022, 7:48am UTC](https://forum.inductiveautomation.com/t/ign-6563-how-to-get-view-name-inside-the-view-itself/63819/6 "2022-09-07T07:48:52Z")

</div>

`self.view.id`  
it puts some extra stuff after the name tho

so you’ll want something like this i guess  
`self.view.id.split('@')[0]`

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [September 7, 2022, 8:15am UTC](https://forum.inductiveautomation.com/t/ign-6563-how-to-get-view-name-inside-the-view-itself/63819/7 "2022-09-07T08:15:32Z")

</div>

@victordcq

`str(self.view.id).split('@')[0]`

Looks good. I tried your suggestion using labels in a host view and a separate embedded view, and this was the result as viewed from Google chrome:

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/5/75538ad99d524792da639d8064b1d1a9a45b1958.png)

---

<div class="post-metadata">

**Author:** ![nader.chinichian](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nader.chinichian/32/9261_2.png) [@nader.chinichian](https://forum.inductiveautomation.com/u/nader.chinichian)\
**Post date:** [September 7, 2022, 10:32am UTC](https://forum.inductiveautomation.com/t/ign-6563-how-to-get-view-name-inside-the-view-itself/63819/8 "2022-09-07T10:32:05Z")

</div>

> [@victordcq](#):
>
> self.view.id

Where did you use this expression? I get error. Could you send me the export of the view.  
I need to get it to work inside the view itself.

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [September 7, 2022, 10:33am UTC](https://forum.inductiveautomation.com/t/ign-6563-how-to-get-view-name-inside-the-view-itself/63819/9 "2022-09-07T10:33:31Z")

</div>

Its a script, not an expression

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [September 7, 2022, 1:12pm UTC](https://forum.inductiveautomation.com/t/ign-6563-how-to-get-view-name-inside-the-view-itself/63819/11 "2022-09-07T13:12:49Z")

</div>

Keep in mind that the view `id` can be supplied by the caller of a popup view instead of being auto-generated.

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [September 7, 2022, 2:39pm UTC](https://forum.inductiveautomation.com/t/ign-6563-how-to-get-view-name-inside-the-view-itself/63819/12 "2022-09-07T14:39:05Z")

</div>

For popups the name infront of the @ `self.view.id.split('@')[0]` will also be the view name.  
Whats after it will be kinda different though, but whats after the @ is rarely any usefull (except maybe debugging/testing)

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/6/f65fcb661a4106cf94f9ef173ce36e0b6e8a708f.png)

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [September 7, 2022, 3:14pm UTC](https://forum.inductiveautomation.com/t/ign-6563-how-to-get-view-name-inside-the-view-itself/63819/13 "2022-09-07T15:14:21Z")

</div>

Yeah, it’s a [ViewInstanceId](https://files.inductiveautomation.com/sdk/javadoc/ignition81/8.1.20/com/inductiveautomation/perspective/gateway/api/ViewInstanceId.html) apparently, which should be consistently usable.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [September 7, 2022, 5:36pm UTC](https://forum.inductiveautomation.com/t/ign-6563-how-to-get-view-name-inside-the-view-itself/63819/14 "2022-09-07T17:36:54Z")

</div>

> [@paul-griffith](#):
>
> which should be consistently usable.

Ok, TIL.

---

<div class="post-metadata">

**Author:** ![nader.chinichian](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nader.chinichian/32/9261_2.png) [@nader.chinichian](https://forum.inductiveautomation.com/u/nader.chinichian)\
**Post date:** [September 7, 2022, 6:01pm UTC](https://forum.inductiveautomation.com/t/ign-6563-how-to-get-view-name-inside-the-view-itself/63819/15 "2022-09-07T18:01:33Z")

</div>

Is there any way to go one level then this?  
I mean the parent view path that calling embedded view.

---

<div class="post-metadata">

**Author:** ![kgamble](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kgamble/32/8019_2.png) [@kgamble](https://forum.inductiveautomation.com/u/kgamble)\
**Post date:** [September 7, 2022, 9:42pm UTC](https://forum.inductiveautomation.com/t/ign-6563-how-to-get-view-name-inside-the-view-itself/63819/16 "2022-09-07T21:42:25Z")

</div>

A callout on being able to access props like `view.id` from an expression, it would be nice if a few more meta props were exposed in expressions directly. I see no reason that `{view.id}` isn’t a valid expression other than it needing to be exposed.

I run into the same problem when trying to show view parameters on a debug label, you cant bind directly to `view.params`, so you need to do something like an expression of `now(2000)` and a script transform that returns `self.view.params`. However then you deal with object wrappers and you need to run extra scripting to convert it (all the way down to its nested objects if deeply nested) into a regular object to interact with it. Being able to bind straight to `view.params` or reference `{view.params}` in an expression would be fantastic.

Its definitely not unheard of to make read only meta props available:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/0/5096bacb7401bf84e052e1f7401f5e05ce8693c1.png)

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [September 7, 2022, 10:14pm UTC](https://forum.inductiveautomation.com/t/ign-6563-how-to-get-view-name-inside-the-view-itself/63819/17 "2022-09-07T22:14:24Z")

</div>

For what it’s worth, I bundled this + [[IGN-6563]Retrieve Session custom props remotely](https://forum.inductiveautomation.com/t/retrieve-session-custom-props-remotely/63840) together on a new internal ticket that’s pretty vague; just suggesting ‘make more things accessible’. Concrete examples (such as `{view.id}` above) _and their use cases_ would be very helpful to add to that ticket.

---

<div class="post-metadata">

**Author:** ![kgamble](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kgamble/32/8019_2.png) [@kgamble](https://forum.inductiveautomation.com/u/kgamble)\
**Post date:** [September 7, 2022, 10:33pm UTC](https://forum.inductiveautomation.com/t/ign-6563-how-to-get-view-name-inside-the-view-itself/63819/18 "2022-09-07T22:33:09Z")

</div>

> [@nader.chinichian](#):
>
> Is there any way to go one level then this?

Get ready for some smelly code, but here goes:

1. Set an outbound prop on your embedded view named `id` with an expression of `false` and a script transform of `self.view`. This should give you the views wrapper address (something like `com.inductiveautomation.perspective.gateway.script.ViewModelScriptWrapper$SafetyWrapper@b95ba6f`)
2. Create a binding with the following code:

```auto
	import time
	# Wait a second for everything to load in
	time.sleep(0.1)
		
	# Get all of the views on the current page
	views = self.view.getPage().views
	
	# Filter out this view, to make things easier
	views = filter(lambda view: view.id != self.view.id, views)
	
	# Create a function that recursively searches components with children
	def searchComponent(component):
		# If there are no children of this component, lets look for the view Id
		if len(getattr(component, "children", [])) == 0:
			# Convert the props to a dictionary so they are easier to use then a PropertyWrapper
			componentProps = dict(component.props)
			
			# Look to see if our outbound Id prop is present and the same
			if componentProps.get('params', {}).get('id') == self.view.params.id:
				# If so, return the parent views path
				return component.getView().id.split('@')[0]
		
		# If we do have children, lets recursively search through them
		else:
			for child in component.getChildren():
				viewId = searchComponent(child)
				
				# If we got a viewId, lets go ahead and jump out of the function with it
				if viewId is not None:
					return viewId
	
	
	
	# Iterate through the views to find any embedded views
	for view in views:
		# Go to the root container and get any of its children
		wrappers = view.getRootContainer().getChildren()
		
		# Go through each of the found top level wrappers and start searching!
		for wrapper in wrappers:
			viewId = searchComponent(wrapper)
			
			if viewId is not None:
				return "Parent: %s" % viewId

	return "Parent: None"

```

The `component.getView().id.split('@')[0]` will give you the path of the parent view.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/b/3b508ceb8ed63c8d2387d0f4b77c20bccf2de5f8.png)

Disclaimer:

1. This doesn't work if you put the embedded view into a container, however it could probably be made recursive to go through any components with children until it finds it.
2. This would be nice if you didn't need the outbound prop, however there is a layer between the embedded view component and the embedded view itself made of 2 safety wrappers and there is no way to get through them directly. The embedded view components safety wrapper has no children, so there is no way to get the components inside of it. And the component of the two is technically different, since they are two different components.
3. This is smelly code and really reliant on the safety wrappers, which ironically feels unsafe

Edit: I made the script recursive for completeness

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [December 1, 2022, 9:19pm UTC](https://forum.inductiveautomation.com/t/ign-6563-how-to-get-view-name-inside-the-view-itself/63819/19 "2022-12-01T21:19:15Z")

</div>

> [@nader.chinichian](#):
>
> page.props.primaryView

I am able to use `page.props.primaryView` when looking at the webpage.

However, when I am in designer, I can't.  
Is there a way to get the view name both in designer and on the web page that I created?

In designer, `page.props.pageID` worked, but that doesn't work when I have my page url set to `/dev1` for testing.

* * *

Never mind, I did an if statement. "Works" in both the designer and the webpage now.  
Had to use `self.page.props.pageId` for the designer side though since my property binding lead with `page.props.primaryView`
