diff --git a/apps/docs/docs/editor/blocks/set-variable.md b/apps/docs/docs/editor/blocks/set-variable.md index 4e4a301f6..9264262c9 100644 --- a/apps/docs/docs/editor/blocks/set-variable.md +++ b/apps/docs/docs/editor/blocks/set-variable.md @@ -6,6 +6,8 @@ The "Set variable" block allows you to set a particular value to a variable. This value can be any kind of plain text but also **Javascript code**. +## Expressions with existing variables + It means you can apply operations on existing variables: ``` @@ -16,14 +18,36 @@ It means you can apply operations on existing variables: {{Score}} * {{Multiplier}} ``` +## Current Date + But also set the variable to the current date for example: -``` +```js new Date() ``` +## Random ID + Or a random ID: -``` +```js Math.round(Math.random() * 1000000) ``` + +## Current URL + +A popular request also is to set a variable to the current URL. Here is the value that should be inserted: + +```js +window.location.href +``` + +It will not give you the parent URL if you embed the bot on your site. A more bullet proof value would then be: + +```js +window.location != window.parent.location + ? document.referrer + : document.location.href +``` + +It checks whether or not the bot is embedded and return the appropriate URL. diff --git a/apps/docs/static/img/blocks/set-variable.png b/apps/docs/static/img/blocks/set-variable.png index fc16939e0..4f81c3f45 100644 Binary files a/apps/docs/static/img/blocks/set-variable.png and b/apps/docs/static/img/blocks/set-variable.png differ