Join the Webstudio community

Updated 8 months ago

Variable Scope

At a glance

The community member created a text variable called "phone" on a page and tried to bind its text to a link element, but received an error saying "No variables available". The comments suggest that variables like this are "static" and can be used in other bindings, but it's better to call resources and bind the variable to that. Another community member suggests that for displaying a phone number in multiple places, it would be better to have it all locally instead of making an API call. The issue was resolved when the community member realized they were trying to set the value of an element inside a Slot component, which doesn't inherit variables yet.

I created a text variable on the page. I called it "phone" and put a phone number in it.

Then I added a link element to the page and tried to bind its text to that variable but it says "No variables available".

Am I misunderstanding how variables work? Or doing it wrong?
Attachments
image.png
image.png
M
H
x
10 comments
Hi! Variable like that are "static". You can use theses variables in other biding. If you need to bind phone's variables, it is better to call Ressources and bind phone's variables.

Ex. : you need to have a phone number like that : + 33 09 56 74 56 67 but you receive data like that :
  • static variable (frenchCode) : +33
  • add Collection with some phone number
In expression editor you coul have something like that : ${frenchCode} ${Phone number frome collection}

Hope I'm clear...
Thanks. Pulling data from a cms or back end makes sense. But some things seem to be better suited to having it all local. If I'm going to display a phone number in 3 different places, it would be cool to enter it once in the designer and have it show up in all 3 places.

Some things like this don't feel like it's worth an api call.
It's not possible to use variable like global variable to use in other page
You have to define variable on the Body
I defined the variable in the body on the page.
I tried to use that variable in an element on the page.
But it said no variables are available.

See the screenshots I posted.
Are you trying to use it in a Slot component? They don’t inherit variables yet
That was exactly the problem. I was trying to set the value of an element inside a slot. Thanks much!!
Add a reply
Sign up and join the conversation on Discord