MIM Prompt Template Json
The *var template node that substitutes AND encodes for you
- clip
- positive
- negative
- positive
- negative
- json
Write your prompt once with *obj and *style style placeholders, drop a JSON object of values in, and this node does two jobs at once: it swaps the variables in, and it encodes the finished prompt straight into conditioning. So instead of "here's a template, go find a text node to render it", you get a node that sits between your templates and the KSampler and just works. It's the anchor of the ComfyUI Prompt Template pack from DaniilVdovin, and the other nodes in the pack are basically variations on this one.
Why reach for it? Two reasons. Reuse - one template, swap the JSON, get a different image without touching the prompt grammar. And variety - the README's selling point is that you can chain several of these, so one set of keys fans out into many different rendered prompts (same key, different values; different keys, same value; that whole cartesian game). If you're coming from the wildcard/bracket-trick school of prompt randomization, this is the structured version: instead of {a|b|c} inline, you keep the variation in one place.
How it works
The mechanism is refreshingly simple: it json.loads your variables_json, then does a plain .replace() on the template for each *key. Whatever the value is gets inserted as literal text. If a clip is connected, the node tokenizes and encodes both resolved prompts into CONDITIONING. If not, it still runs - which turns out to be useful (see below).
The inputs that matter
- template_positive - your template with
*obj,*place, etc. (defaultA *obj on a *place). - template_negative - same syntax, for the negative.
- variables_json - the values, e.g.
{"obj": "cat", "place": "table"}. - clip - optional, but connect it unless you specifically want text-only.
Outputs: positive and negative CONDITIONING (wire into the KSampler), then positive and negative STRING (the resolved raw prompts - handy for a preview text node or to feed another template), plus a json STRING that echoes your variables back out for chaining.
Installing
No dependencies at all - the pack is pure Python stdlib, no requirements file, no models to fetch. Manager route: search "ComfyUI Prompt Template". Or:
cd ComfyUI/custom_nodes
git clone https://github.com/DaniilVdovin/ComfyUI-prompt-templating.git
Then restart ComfyUI.
Where people get burned
- Malformed JSON fails silently. A missing brace means
variables = {}and your*objstays literally in the prompt - no error, no warning, just a prompt that suddenly has asterisks in it. If you see a stray*in your render, check the JSON first. - Variable names are prefix-sensitive. Replacement is a naive
.replace(), so if you have*objand*obj2, resolving*objfirst mangles*obj2(it becomes<value>2). Keep names distinct, like*subjectand*background. - Disconnect clip only on purpose. With no clip the conditioning outputs are degenerate, so use this as a text-only node (the STRING outputs) or leave clip attached.
*varand{a|b|c}stack. The template fields are flaggeddynamicPrompts, so with ComfyUI's Dynamic Prompts toggle on you can combine bracket randomization with your substitutions - one node doing both layers of variety.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| clipopt | CLIP | — | |
| template_positiveopt | STRING | A *obj on a *place | — |
| template_negativeopt | STRING | — | |
| variables_jsonopt | STRING | {"obj": "cat", "place": "table"} | — |
Outputs (5)
| Name | Type | Description |
|---|---|---|
| positive | CONDITIONING | — |
| negative | CONDITIONING | — |
| positive | STRING | — |
| negative | STRING | — |
| json | STRING | — |