Apply Text Template (mtb)
Build prompts from a template with variables in ComfyUI
- string
Apply Text Template (mtb) lets you write a prompt with blanks in it and fill those blanks from other nodes. You type a template like a photo of a {var_1} in a {var_2}, wire the values in, and it spits out the assembled string. It's basic string interpolation, and it's one of those quiet workhorses for anyone who builds prompts programmatically.
Why bother instead of just typing the prompt? Because the fill-ins can come from anywhere - a wildcard picker, a random selector, an LLM caption node, a counter, a value that changes per batch. You keep one fixed prompt skeleton and vary the pieces. That's the whole trick behind systematic prompt exploration: hold the structure constant, swap {var_1} across a list of subjects, and generate a clean matrix of variations without rewriting the prompt every time.
It's in the utils section of MTB Nodes (comfy_mtb) by melMass, and its click-through in search suggests people go looking for exactly this.
How it works
It uses dynamic inputs with a fixed naming convention. The variable slots are named var_1, var_2, and so on, and in your template you reference them with curly braces: {var_1}, {var_2}. When the node runs, it substitutes each connected value into its matching placeholder and returns the finished text. Add another input and you get var_3 to reference, and so on - the node grows as many slots as you wire up.
The inputs and outputs that matter
template(multiline string) - your text with{var_1},{var_2}… placeholders where the fill-ins go. This is the one field you type into.- the variable inputs - dynamic slots named
var_1,var_2, etc. Wire a value into each, and it lands in the matching{var_n}in the template.
Output is a single string - the fully substituted text, ready to feed a CLIP Text Encode or any node that takes a prompt.
The naming is the thing to internalize: the n-th input is var_n, and you must reference it in the template as {var_n} exactly. Get the number or the braces wrong and the placeholder just won't fill.
How to install it
ComfyUI Manager: search MTB Nodes, install, restart. Manual:
cd ComfyUI/custom_nodes
git clone https://github.com/melMass/comfy_mtb
then restart. Pure Python - no models, nothing to download.
Common issues & troubleshooting
A placeholder printed literally instead of filling. The template still shows {var_1} in the output? Either nothing's connected to that slot, or the name/braces don't match. It has to be {var_1} (underscore, exact number) and the corresponding input has to be wired. A typo like {var1} or {Var_1} won't match.
The values need to be strings. The fill-ins are dropped in as text, so pass string-compatible values. If you're feeding a number, convert it first (Any To String in this same pack does that) so it substitutes cleanly.
Extra or missing braces. Interpolation keys on the exact {var_n} pattern. A stray { or a missing } breaks the placeholder around it. If a chunk of your template vanished or came out mangled, check the braces.
Slots don't appear. Like other dynamic-input MTB nodes, the next var_ slot shows up once you connect the current empty one. Connect what's there and the next input appears.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| template | STRING | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| string | STRING | — |