Skip to main content

Dynamic Shortcodes Variables (set and get)

Updated over a week ago

Variables can be defined with either the for or the let Shortcode, these variables are only valid while their respective Shortcodes are being evaluated.

If a variable is redefined in a nested scope, the previous variable is hidden until the end of the nested scope (shadowing).

The for Shortcode is documented in its respective page.

Set Shortcode

Used to set the value of a variable. First argument is the variable name, second name is the new value.

Examples:

{set:x 3}

set the value of x to 3.

{set:x {+: $x 1}} 

increment x by one.

If you use the set Shortcode on an undefined variable, a variable will be created that is not bound to any scope, it will be valid also after the end of the current scope.

There is also set-default, it will set a value only if the specified variable has not already been initialized. If the variable has been initialized it does nothing.

Get Shortcode

Used to get the value of a variable. If the variable doesn't exist it throws an error. Example

{get:x} {get:foo}

If you already are inside a shortcode you can just write $foo, which is just the same as writing {get:foo}, for example {+:$foo 1} instead of {+:{get:foo} 1}

Did this answer your question?