#
Macros
Experimental Macro Engine
To enable advanced macro processing that supports nesting, stable substitution order, and other improvements, go to User Settings > Chat/Message Handling and enable the Experimental Macro Engine option.
Macros are dynamic placeholders that get replaced with actual values when text is processed. They are used throughout SillyTavern in prompts, character cards, lorebooks, Quick Replies, and more.
#
Finding Available Macros
SillyTavern provides built-in documentation for all available macros:
- Slash command: Type
/? macrosin the chat input to display a list of all registered macros with their descriptions. - Autocomplete: Type
{{during slash commands autocomplete in the input field to get suggestions for available macros.
#
Basic Syntax
Macros are enclosed in double curly braces:
{{macroName}}
Macro names are case-insensitive. {{User}}, {{USER}}, and {{user}} all resolve to the same macro.
Examples:
{{user}} // Returns the current user/persona name
{{char}} // Returns the current character name
{{time}} // Returns the current time
{{date}} // Returns the current date
#
Arguments
Many macros accept arguments to customize their behavior.
#
Space Separator
For macros with a single argument, a space can separate the macro name from its argument:
{{macroName argument}}
Examples:
{{getvar myVariable}}
{{roll 1d20}}
{{reverse Hello World}}
#
Double Colon Separator
Use :: to separate multiple arguments:
{{macroName::arg1::arg2::arg3}}
Examples:
{{setvar::myVariable::Hello World}}
{{random::red::green::blue}}
{{roll::2d6+3}}
Both space and :: are the recommended syntax for macro arguments.
#
Single Colon Separator (Legacy)
A single : can also introduce arguments, but this syntax is considered legacy and not recommended for new content:
{{macroName:argument}}
Examples:
{{roll:1d20}}
#
Whitespace in Macro Definitions
Whitespace between the macro name, separators, and arguments is ignored. This allows for more readable formatting:
{{ macroName :: arg1 :: arg2 }}
{{ setvar :: myVariable :: some value }}
{{ if :: condition }}
All of the above are equivalent to their compact forms without extra spaces.
#
Nested Macros
Macros can be nested inside other macros. Inner macros are resolved first:
{{getvar::{{char}}_mood}}
This first resolves {{char}} (e.g., to "Alice"), then resolves {{getvar::Alice_mood}}.
More examples:
{{setvar::greeting::Hello, {{user}}!}}
Sets a variable with content that includes the user's name.
{{if {{getvar::showDetails}}}}Details here{{/if}}
The condition itself is a macro that retrieves a variable value.
#
Scoped Macros
Staging Feature
This is currently only available on the staging branch of SillyTavern, and not part of the latest release.
Any macro that accepts at least one argument supports scoped syntax. The content between opening and closing tags becomes the last argument of the macro.
#
Scoped Syntax
Instead of writing the last argument inline, it can be placed between opening and closing tags:
{{macroName argument}}
scoped content here
{{/macroName}}
The closing tag uses the / flag before the macro name: {{/macroName}}.
This is equivalent to writing:
{{macroName::argument::scoped content here}}
#
Examples
Setting a variable with multiline content:
{{ setvar backstory }}
This character was born in a small village
and grew up to become a renowned scholar.
{{ /setvar }}
Using reverse with scoped content:
{{ reverse }}
Hello World
{{ /reverse }}
This returns "dlroW olleH".
#
Content Trimming
By default, scoped content is automatically trimmed:
- Leading and trailing whitespace is removed
- Consistent indentation is de-dented (the indentation of the first non-empty line is removed from all lines)
This allows clean formatting:
{{ if condition }}
# Heading
Some content here
{{ /if }}
Produces # Heading\nSome content here (without the leading spaces).
To preserve all whitespace including leading/trailing newlines, use the # flag. See
#
Conditional Macros
Staging Feature
This is currently only available on the staging branch of SillyTavern, and not part of the latest release.
The {{if}} macro renders content conditionally based on whether a value is truthy or falsy.
#
Simple Condition
{{ if description }}
# Character Description
{{ description }}
{{ /if }}
This displays the heading and description only if description returns a non-empty value.
The condition can be:
- A macro name (resolved automatically if no arguments are required)
- Any value from a nested macro like
{{getvar::flag}} - A variable shorthand like
.myFlagor$globalFlag(seeVariable Shorthand Syntax ) - Any text you want (that will implicitly resolve to truthy or falsy based on its content)
Falsy values: empty string, false, 0, off, no.
#
Using Variable Shorthands in Conditions
Variable shorthands provide a concise way to check variable values in conditions:
{{ if .isEnabled }}
Feature is enabled.
{{ /if }}
{{ if !$globalDisabled }}
Not globally disabled.
{{ /if }}
See
#
Inverted Condition
Prefix the condition with ! to invert it:
{{ if !personality }}
No personality defined for this character.
{{ /if }}
#
If/Else Branches
Use {{else}} inside an {{if}} block to define an alternative branch:
{{ if personality }}
{{ personality }}
{{ else }}
No personality defined.
{{ /if }}
Another example:
{{ if {{getvar::details-block}} }}
# Details Block
{{ getvar::details-block }}
{{ else }}
No details currently exist.
{{ /if }}
#
Macro Flags
Staging Feature
This is currently only available on the staging branch of SillyTavern, and not part of the latest release.
Flags are special symbol characters placed between the opening braces and the macro name that modify macro behavior.
#
Syntax
{{!macroName}}
{{#macroName}}
Flags can be combined:
{{!?macroName}}
Whitespace is allowed between flags and the macro name:
{{ / macroName }}
{{ # macroName }}
#
Implemented Flags
#
Planned Flags (Not Yet Implemented)
#
Flags-like prefix operators
Variable shorthand syntax uses prefix operators (. and $) which behave similarly to flags but are not flags themselves.
See the
#
Preserve Whitespace Flag
Use the # flag when you need to preserve all whitespace in scoped content, including leading/trailing newlines and indentation:
{{ # setvar code }}
function hello() {
return "world";
}
{{ /setvar }}
Without #, the content would be trimmed and dedented. With #, all whitespace is preserved exactly as written—including the newline after the opening tag and before the closing tag.
#
Comments
Use the comment macro to add notes that won't appear in the output:
{{// This is a comment and will be removed}}
For multi-line comments, use scoped syntax:
{{ // }}
This entire block is a comment.
It can span multiple lines.
{{ /// }}
#
Escaping Macros
To display literal curly braces without macro resolution, escape them with backslashes:
\{\{notAMacro\}\}
This outputs {{notAMacro}} as plain text.
#
Variable Shorthand Syntax
Staging Feature
This is currently only available on the staging branch of SillyTavern, and not part of the latest release.
Variable shorthands provide a concise syntax for common variable operations. Use . for local variables and $ for global variables.
#
Variable Shorthands Prefix Operators
These prefix operators have to be placed immediately before the variable name, after any optionally appearing
#
Getting Variables
Retrieve variable values with a simple prefix:
{{.myvar}} // Get local variable "myvar"
{{$myvar}} // Get global variable "myvar"
Equivalent to {{getvar::myvar}} and {{getglobalvar::myvar}}.
#
Setting Variables
Use the = operator to set a variable value:
{{ .myvar = Hello World }} // Set local variable
{{ $myvar = Some value }} // Set global variable
Equivalent to {{setvar::myvar::Hello World}} and {{setglobalvar::myvar::Hello World}}. Returns an empty string.
#
Increment and Decrement
Use ++ and -- to increment or decrement numeric variables:
{{.counter++}} // Increment local variable, returns new value
{{$counter--}} // Decrement global variable, returns new value
Equivalent to {{incvar counter}} and {{decglobalvar counter}}.
#
Add to Variable
Use += to add a numeric value to a variable:
{{.score += 10}} // Add 10 to local variable
{{$total += 5}} // Add 5 to global variable
Equivalent to {{addvar::score::10}} and {{addglobalvar::total::5}}. Returns an empty string.
The add operator also supports appending string to an existing string macro, if neither of them are numbers.
{{.myvar += {{noop}} | Second block}} // Resolves to "Content | Second block" when the variable before was "Content".
// Use `{{noop}}` to be able to add whitespaces, that otherwise would be trimmed automatically.
#
Nested Macros in Values
Variable values can contain nested macros:
{{.greeting = Hello, {{user}}!}}
Resolves to a variable that that saves Hello, User! inside. (If {{user}} is named "User")
#
Whitespace Handling
Whitespace around operators is allowed:
{{ .myvar = spaced value }}
{{ .counter ++ }}
#
Variable Names
Variable names follow the same rules as macro identifiers: start with a letter, followed by letters, digits, underscores, or hyphens. The last character is not allowed to be an underscore or hyphen.
{{.my-var}} // Valid
{{.my_var}} // Valid
{{.myVar123}} // Valid
If your variable has an identifier that does not match the standard rules, you have to use the full variable macro syntax with angle brackets (e.g. {{getvar::my§var----}}), or rename/move your variable value.
#
Legacy Syntax
For backwards compatibility, angle bracket markers are still supported:
These are automatically converted to their macro equivalents during processing.
Note: Legacy syntax is not recommended. Use the equivalent
{{macro}}syntax instead for new content.
#
Common Macros by Category
Use /? macros for the complete list of available macros and their detailed descriptions.