Join the Webstudio community

Updated 7 months ago

Variable Scope

At a glance
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