Binding works in designer but not in browser

Hey guys I've been working on making template views that change content based on provided parameters

I have an accordion that i do not want to display when my view.params.apm_id = 1

here is the binding on the display property:
if (
{view.params.apm_id} = 1,
false,
true
)

in the designer when view.params.apm_id = 1 the accordion is hidden but on the browser it is not

any help would be greatly appreciated

This probably isn't the issue, but that expression can be simplified to just:

{view.params.apm_id} != 1

2 Likes

That does simplify it, I didn't realize I could do that, thank you. However yes it didn't fix my issue

You may try use == instead =

You may not. That's script (Python) syntax. This thread seems to be about an expression.

Try
!{view.params.apm_id}

1 Like

it shouldn't be the expression that is the issue. It works in the designer and appropriately hides the accordion when view.params.apm_id = 1 however in a web browser it does not hide it when view.params.apm_id = 1

designer (when apm_id != 1):

designer (when apm_id = 1, notice how steam accordion disappears):

in browser when apm_id = 1:

Notice how the steam accordion is displaying in the browser when it should be hidden like the designer when apm_id = 1? Also APM # at the top is displaying {view.params.apm_id} thats how I know it is 1

Don't know where your parameters are coming from, but you can throw a label on the view temporarily and double check that the datatype is what you expect it to be (int vs string)

Maybe it's a security thing? Are you logged in on the browser as well? I noticed that your Valve Position binding is bad as well

I wasn't evening thinking about that

I pass my apm_id parameter through the url like so
image

and this is the class, which would definitely explain why it doesn't work in a browser. I ASSUMED it would be automatically casted into a number but I was wrong
image

I haven't figured out exactly what you are trying to do, but parameters are only read when the view first loads. That means that you can't use a view parameter to switch something on and off.

Instead, pass in the tag path as a parameter and create a binding inside the view to control whatever it is you want.

Are there any risks possible when allowing the user to select an arbitrary tag path to read from? Eg, they can manually change the URL to inspect any true/false tag, in theory.

Probably better to have it get only part of the tag path, so you can limit the area to only one folder of tags.

Yes that is why I was using params, I figured out the problem and it was because it was loaded as unicode on perspective because it was a page parameter

image

so I just adjusted my binding to this:

and now it works in both perspective and the designer

Did you try the expression language's type coercion? toInt({view.params.apm_id}) != 1. Should be equivalent to (and faster and lighter weight than) your script transform. (It would remove the need for a transform entirely)

If this is a parameter being passed in via URL I believe all URL parameters are treated as strings.

4 Likes

I would still stick with the Expression transform over Script, as they execute significantly faster. It may not matter much for such a simple expression, but it's a good rule in general.

5 Likes

Thank you I was not aware I could use an expression to convert types

Docs for all the available expression functions:

2 Likes