Using Template Syntax (EJS) in Prompt
This extension supercharges SillyTavern's macro system, enabling you to use full-fledged JavaScript within your prompts, character cards, and World Info. It leverages EJS (Embedded JavaScript templating) to bring dynamic logic, conditions, loops, and advanced variable management directly into your creative workflow.
Go beyond simple text replacement and create truly dynamic and responsive AI interactions.
[GENERATE:BEFORE] in a World Info entry's title to inject its content at the start or end of the prompt context.@INJECT syntax for fine-grained control, allowing you to insert entire messages ({role: 'system', content: '...'}) at absolute positions, relative to other messages, or based on regex matches.getvar, setvar, getwi, getchar) to interact with SillyTavern's data, manage state, and fetch content dynamically.global, local (chat-specific), and even message-specific variables that persist across sessions.Simply use EJS tags in any text field that gets sent to the LLM. The extension will process them at the appropriate time.
Example 1: Simple Output Display a variable's value in a character's prompt.
// In a World Info entry or character definition
Character's current affinity: Example 2: Conditional Logic Change the prompt based on a variable.
50) { %>
You are my trusted friend.
I'm still wary of you.
Example 3: Updating Variables from LLM Output Let the LLM's response modify the character's state.
// LLM generates this message
Your kindness has been noted. My affinity for you has increased.
New affinity: The user will see the message with the updated affinity value, and the affinity variable will be saved for future interactions.
For a complete guide to all features and advanced usage, please see:
_, faker, etc.).This project is open-source and available under the AGPL-3.0 License.
No open issues yet, or sync has not completed.