I’m looking to figure out how to create a template in perspective. I ran into this post from 2021
Is this still the answer? with the project I’m creating this would be 40+ embedded views just for one view, which seems a bit excessive. is there a better way to creating templates in perspective? we are not using vision for this project. any suggestions are welcome
Embedded Views is how you instance templates. So what are templates? Basically, any view. I put all of our template views under a folder called “Templates” for consistency. The parameters can be used to do indirection, so you don’t have to create 40+ independent views.
Just wanted to add that IA has done a lot of work in the last 4 years with improving the performance of embedded views. You still don't want many nested layers of embeded views, but a few is generally fine.
really its my main view, which has a few embedded views on it to form the main screen. then within my embedded views i would have my “template” views? correct?
The best way to know if you’re going to have a problem is to build a test template and see how it performs. I believe the performance issue manifests most frequently with multiple nested layers of templates and I suspect larger number of parameters may impact performance.
It’s a good practice to build a UDT that contains all the stuff you need for your template and then pass in a tag path to the UDT instance so you can indirect bind all the tags on template from your UDT.
I’ve done way more than 40 instances of a single template on a screen with no performance impact (fast load). If you’re using SVGs in your template make sure you use optimized SVGs (small file size) to reduce load times.
One time I did a template test with about 1000 instances of a device template embedded as a view on the same screen. It loaded in about 3 seconds and responded to tag updates in about a second.
I said nested which is a bad word choice. What I mean is if you have a template that is built from templates which are built from templates and so on.
So it’s not like a recursive nesting thing. It’s if you have lots of lairs of nested templates.
I’ve gotten away with embedding multiple layers deep (4 or 5) but you have to test it and make sure the performance is suitable. That’s why I recommend templating it and making sure it is giving you the performance you want before you build the whole solution.
If you are talking about how they show up in the desinger, that is just how they show up when you embed an SVG. As far as I know its always been that way in 8.1
my next question would, let say i have a template for a tank and i want it to do; on click event: pull an overlay to the main screen. but each tank could have different statistics so I want to be able to configure each one to display their own stats. is there a way to make the “template” do an on click event but be able to change each individual tank to make that onclick event pull their own stats? if that makes any sense.
before i made the templates i was doing it through message handlers, is it still possible that through the use of them but in a template mode?
Make your template's onClick script generic, just take the tank Id/string path that was passed to the template, and pass them as parameters to the statistics overlay on the main screen. The statistics overlay should be built in a similar fashion to the template, where all it needs is the base tag path string to build the indirect bindings to any statistics tags for the given tank. If you are using any SQL queries then make them use the tank ID as a parameter.
All of this comes down to tag organization. Group tags by their associated tank. If you want, you can technically separate by realtime vs statistics, as long as you maintain a consistent layout/format.
atm my onclick event script is “system.perspective.sendmessage()” so i want to have whats in the () be configurable for each tank? so ill want to be able to set it to “…sendmessage(‘tank1’)” , “…sendmessage(‘tank2’)” etc. for each instance
I havnt started setting up tags yet, just working on layouts of the screens, im just curious about navigation
system.perspective.sendMessage expects a dictionary payload. Pass identifying information inside of the message's payload, and have the targeted message handler inspect the payload for said identifying information to determine if it should do something or ignore the message.
self.view.params.tankId would be the tank id that was passed to the template. You can reference properties on the template in your scripts. This allows your onClick script to be generic while still passing the necessary identifying information to other templates/windows/scripts.
edit: For what it's worth, navigation using system.perspective.navigate also allows you to pass a dictionary of parameters to send to the view you are navigating to.
@cseigworth16, please capitalise and punctuate your posts properly as they are difficult to read otherwise and it shows some disrespect to those you are asking to give of their time to help you. Your compiler wouldn't let you away with it - why should we?