Nodes/ComfyUI-Combine-Strings-Template/Replace String Literals
ComfyUI Node

Replace String Literals

Your template's $0, $1 placeholders just became real inputs

By SergeBekenkamp·Created 3 months ago·Updated 3 months ago· 0
Replace String Literals
  • strings
  • STRING
template$0

Every ComfyUI workflow eventually turns into a pile of Text nodes feeding a single prompt, and the pile gets old fast. Replace String Literals is the small, honest answer: you write a template once with $0, $1, $2 placeholders, and each placeholder pulls in its own connected string input. Change one socket, the whole template updates. It's the same mental model as Python's str.format() or a shell script's $1 - if you've used either, you already know this node.

It lives in the utils/string category, and the whole pack is just this one node plus its extension wrapper. Nothing downloads, nothing calls an API, there's no model file. It's pure string plumbing.

How it works

Under the hood it's a single regex - \$(?:\{(\d+)\}|(\d+)) - scanning the template and swapping each match for the value on the matching socket. The placeholders are positional: $0 reads the socket named string0, $1 reads string1, and so on. Two syntaxes:

  • $N - the bare form: $0, $1, $10
  • ${N} - the braced form: ${0}, ${1}

You want the braced form whenever a digit would otherwise glom onto the placeholder. $10 means index ten, not $1 followed by a 0; if you meant index 1 followed by the digit 0, write ${1}0. That greedy-digit rule is the one genuine trap here, and it's the reason the ${} syntax exists at all.

One behavior worth knowing: an unmatched placeholder is kept literally. If you type $7 but only wire up string0 through string4, the output will contain the literal text $7. That's usually helpful - it means the node won't blow up on a sloppy template - but it also means a typo like %0 instead of $0 silently sails through. If your prompt shows up with a stray $ in it, check your template text, not your graph wiring.

The inputs that matter

The node is refreshingly small:

  • template (multiline string, default $0) - the text with $0, $1, … placeholders. Because it's multiline you can paste a whole multi-tag prompt in here.
  • strings - the autogrow socket group. Click to add up to 50 string inputs (string0, string1, …). This is where the dynamic parts of your prompt plug in.

Output: a single STRING. Wire it straight into a Checkpoint Loader's positive prompt, a sampler, or into another string node for further chaining. It's not an output node - it produces text, it doesn't display it - so if you want to eyeball the result, run it through a node that shows its value.

Where it shines: keep the boring skeleton of a prompt fixed (quality tags, framing, lighting boilerplate) and swap only the subject, style, and negative-prompt sockets. Or use it as a poor man's wildcard - one template socket per concept you batch over.

Installing it

Via ComfyUI Manager, search "ComfyUI-Combine-Strings-Template" (or the node name) and install. Manual route:

cd ComfyUI/custom_nodes
git clone https://github.com/SergeBekenkamp/ComfyUI-Combine-Strings-Template.git comfyui_replace_string_literals

Restart ComfyUI. That's it - no requirements.txt, no extra Python deps, pure stdlib plus ComfyUI's own API.

Gotchas

The one real requirement: this node is written against the modern extension API (comfy_api.latest), so it needs a reasonably current ComfyUI. On an old pinned install it simply won't appear - update ComfyUI first. And if you're on the legacy canvas while other packs are still catching up to Comfy's Nodes 2.0 rewrite, this node is one of the small ones that migrated cleanly, so it tends to render fine where the big packs still hiccup. Small, boring, dependency-free - in the current custom-node ecosystem, that's a feature.

Categoryutils/string

Inputs (2)

NameTypeDefaultDescription
templateSTRING$0Template string. Use $0, $1, ... or ${0}, ${1}, ... to reference connected string inputs by index. Unmatched placeholders are kept literally.
stringsCOMFY_AUTOGROW_V3

Outputs (1)

NameTypeDescription
STRINGSTRING