Macro reference
Marginalia understands the macros of SillyTavern, so prompts and world info written for SillyTavern work without changes. Macros work in every template: master template, user prompt, summary prompt and lorebook entries.
Syntax
- Macro names are case-insensitive:
{{User}}and{{USER}}work. - Spaces around names and arguments are ignored:
{{ getvar :: mood }}. - Extra
::go into the last argument:{{setvar::x::a::b}}setsxtoa::b. - Scoped content is evaluated first, then dedented and trimmed. With
#after the braces,{{#setvar name}}...{{/setvar}}, the whitespace is kept exactly.
Names and participants
Marginalia has no personas or character cards; the names come from the turn instructions of the part being written.
The SillyTavern markers <USER>, <BOT>, <CHAR>, <GROUP> and <CHARIFNOTGROUP> (any case) work as well.
With POV character Alice and present characters Alice, Bob, Carol:
{{user}} → Alice, {{group}} → Alice, Bob, Carol, {{notChar}} → Bob, Carol.
Story history
For the first part of a book they are empty. For Regenerate, "last part" is the one before the regenerated part.
Date and time
Times are in the time zone of the computer or server Marginalia runs on, and always in English. For the
Docker version, set the time zone with the TZ environment variable, e.g.
TZ=Europe/Prague.
Variables
Variables store values between parts: counters, a character's mood, things the story has established. There are two kinds:
-
local variables belong to the story branch: each part remembers their values, and a new part starts with the values of the part before it;
-
global variables belong to the book, shared by all branches.
See What is kept between parts.
Numbers are printed without trailing zeros: 1.50 plus 1.5 is 3.
{{setvar::hp::10}}{{addvar::hp::5}}HP: {{getvar::hp}} → HP: 15
{{setvar::items::a rope}}{{addvar::items::, a lamp}}{{getvar::items}} → a rope, a lamp
Shorthands
{{.name}} is a local variable, {{$name}} a global one. On its own, a shorthand prints the value. With an operator:
Fallbacks and defaults:
{{.name || Guest}}prints Guest when the variable is empty or falsy (0,false,no,off);{{.name ?? Guest}}prints Guest only when the variable isn't set at all;{{.title ||= Wanderer}}sets the variable to Wanderer if it is empty or falsy, then prints it;{{.title ??= Wanderer}}sets it only when it isn't set at all, then prints it.
Values can contain macros: {{.log += -> {{user}}}}.
A part counter, for example, at the top of the user prompt (+= prints nothing, and {{trim}} removes the empty
line it leaves):
{{.part += 1}}{{trim}}
This is part {{.part}} of the story.
Conditionals
{{if presentCharacters}}
Present: {{presentCharacters}}
{{else}}
{{user}} is alone.
{{/if}}
The condition can be:
Falsy are an empty value and 0, false, no, off (any case). Everything else is true.
-
The short form
{{if user::text}}prints text when the condition is true. -
Only the branch that is taken is evaluated: a
{{setvar}}in the other branch doesn't happen. -
{{if}}blocks are dedented and trimmed like scoped macros, so they can be indented for readability.{{#if}}(the Handlebars if) keeps the whitespace. -
A
{{if}}without{{/if}}is printed as text.
Randomness
Generation info
Utility
SillyTavern-only macros
Macros that only make sense in SillyTavern chats - personas and character card fields ({{persona}},
{{personality}}, {{charPrompt}}, {{mesExamples}}...), instruct mode sequences ({{instructUserPrefix}}...),
author's notes, swipe IDs, {{outlet}} and the like - are recognized and print nothing, so imported world info
doesn't leak them into the prompt. {{isMobile}} and {{hasExtension}} print false.
A macro Marginalia doesn't know:
- with arguments (
{{fooBar::x}}) is printed as it is, like SillyTavern does; - without arguments (
{{fooBar}}) is printed asError, the same as an unknown template variable.