Pass external variables
Sometimes you may want to pass variables to your embed without having to declare them inside Toucan Toco because it depends on the specific context of your application.
To do so, you can pass down your variables in embeds scripts:
As you can see, you can add any key to our variables
parameter. If you have to pass 2 parameters, for instance, youโll have to write:
Important
To support object
and array
type, weโre parsing each variable. Make sure you have encoded it well using JSON.stringify
When it comes to passing down a lot of variables, including object
and array
, weโre suggesting encoding a complete variables
object and declaring all those extra variables into the extra
key as follows:
Example
Setup in a story
After that, you can use your variables in the configuration of your story. Thanks to extraVariables
you can template your variable inside the story. For example, you can set a contextual commentary
.
IMAGE
Now youโve got an error because the variables arenโt interpolated !
IMAGE
Note that you can display a default value to avoid that state.
IMAGE
You should now have default value
interpolated.
IMAGE
Last updated