[Feature-1739]Perspective Relative Path for Embedded View, Flex Repeater, etc

It would be nice to be able to optionally reference other views via a relative path in the path prop. For example, in this image if we could reference ‘./Realistic’ instead of ‘Components/Pump/Symbol/Realistic’ I could then rename the folder or move everything to a different folder without breaking the references.

1 Like

Hacky workaround:

Bind the path property with a property binding on any property (you actually need access to the transform part of the binding).
Add a transform to the binding.
Supply the following script: return "/".join(self.view.id.split("/")[:-1]) + "/desiredViewName" where “desiredViewName” is the name of the View you want a relative position of.

In this example, I bound against view.props.loading.mode, but I don’t need that value - I just need the transform. Note the returned value in the binding dialog preview area.

With that binding in place, I was able to drag my something directory around into different locations of my View directories and the references to other Views within the directory remained functional.

5 Likes

Perfect! I was attempting to implement a workaround like this and that self.view.id property is what I was looking for. That will get me going for now. Thanks!

1 Like

I’ll suggest self.view.id[:self.view.id.rfind('/')], which avoids spliting and joining.
It might be less readable when dealing with this kind of variable, but this can easily be fixed by assigning the string to another var, which actually makes the whole thing more readable than the initial solution in my opinion:

Is this actually a bad solution ?

2 Likes

@pturmel, can the Integration Toolkit be used to execute this Python script?

 "/".join(self.view.id.split("/")[:-1]) + "/desiredViewName"

where is not a python keyword, and no amount of integration toolkit will change that.

What are you trying to do ?

1 Like

I mean the .join.
The where was the comment which I mistakenly copy from original post.

So what you want is the expression equivalent of this python code ?

Sure, with objectScript. But for best performance, I'd make a pure expression with groupConcat(), where() and split().

groupConcat(
	transform(
		forEach(
			split({view.id}, '/'),
			it()[0]
		),
		asPairs(
			where(
				value(),
				idx() < (len(value())-1)
			),
			asList(
				'desiredViewName'
			)
		)
	),
	'/'
)
1 Like

That's what I meant. Perfect. Thanks, Phil. Of course, the only reason I ask for this is the performance.

I just realized this is probably faster:

groupConcat(
	transform(
		split({view.id} + "/desiredViewName", '/'),
		where(
			value(),
			idx() != (len(value())-2)
		)
	),
	0,
	'/'
)
1 Like