Replace Variables and Process Wildcard (Loop)
Chain variables, wildcards, and cleanup in one node — with a loop for the nasty nesting
- prompt
This is the pack's flagship - the node that ties everything else together. It takes text that can contain $variable="value" definitions, $variable references, and __wildcard__ / {a|b|c} expressions, then runs "replace variables → expand wildcards" in a loop, loop_count times, and optionally cleans up the result.
The loop is the point. When a variable's value contains a wildcard, or a wildcard file contains variable references, a single pass isn't enough - one substitution unlocks new text that itself needs expanding. The README's example is $adj="beautiful" $thing="__objects__" A $adj $thing → A beautiful flower. Notice $thing's value is a wildcard; only the second pass resolves it. That's what makes this node more than just two nodes glued together.
How it works, in order
- Extract every
$name="value"definition and delete them from the text. loop_counttimes: substitute$namereferences, then run Impact Pack's wildcardprocess()with your seed.- Optionally strip
$varreferences that were never defined (remove_undefined_variables, off by default). - Optionally run the Conditional Tag Processor's
<ADD:...>/<REMOVE:...>pass exactly once at the end (process_conditional_tags). - Optionally remove linefeeds (
No/All/Blank Lines Only) and normalize commas (collapse doubles, fix spacing, dropBREAK,and trailing commas).
The two cleanup toggles are the same code the Remove Comments node uses, so behavior carries over.
Inputs that matter
text(STRING,forceInput, multiline) - noteforceInput: this field is meant to be wired from another node, not typed. The whole point is text flows in from upstream.seed(INT) - makes the wildcard roll reproducible.loop_count(INT, default 1, min 1) - replace→expand passes. Start at 1; raise it only when something isn't resolving.remove_linefeed,normalize_commas,remove_undefined_variables,process_conditional_tags- the post-processing toggles, all off by default.- Output:
prompt(STRING) → your text encoder.
Where it fits
You've got a batch pipeline that mixes templates, per-run variables, and random wildcard choices - this collapses what would be four or five nodes into one. It's also the gentlest way to try the Conditional Tag Processor: flip process_conditional_tags on and put your <ADD:...>/<REMOVE:...> directives in the text, no separate node needed.
Troubleshooting
- Requires ComfyUI-Impact-Pack. The wildcard engine is Impact Pack's; without it the node fails at import or run. Install Impact Pack first, then this pack, restart.
- If
remove_undefined_variablesis off (default) and an unresolved$nameshows up in the output as literal text, the definition was probably misspelled or its value wasn't in double quotes. - Values must be
"quoted"-$thing=__objects__without quotes isn't a definition. - Loop count isn't free: every pass re-runs wildcard processing, and runaway nesting (a wildcard whose value expands back to itself) is theoretically possible. Keep
loop_countsmall and intentional.
Installing
cd ComfyUI/custom_nodes
git clone https://github.com/ltdrdata/ComfyUI-Impact-Pack # first - required
git clone https://github.com/watarika/ComfyUI-Text-Utility
# restart ComfyUI
Or via ComfyUI Manager for both. No pip requirements, no models in this pack.
Inputs (7)
| Name | Type | Default | Description |
|---|---|---|---|
| text | STRING | — | |
| seed | INT | 00–18446744073709550000 | Determines the random seed to be used for wildcard processing. |
| remove_linefeed | COMBO | 3 options: No, All, Blank Lines Only | |
| normalize_commas | BOOLEAN | false | — |
| remove_undefined_variables | BOOLEAN | false | — |
| process_conditional_tags | BOOLEAN | false | — |
| loop_count | INT | 1 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| prompt | STRING | — |