π Text Template (nhk)
Fill-in-the-Blanks Prompts, Done Properly β Text Template (nhk)
- output
Text Template (nhk) is a fill-in-the-blanks engine for your prompts. You write a template like The [a] walks in the [b], wire strings into the [a] and [b] slots, and get a fully assembled sentence on the output. The default template is literally that dog-walking sentence, so the author's intent is clear: this is prompt-building, not code.
Where this shines is prompt variation. Instead of four copies of a CLIPTextEncode with different adjectives, you keep one template and swap the slot values - ideally with a switch or cycling node driving [a] from a list. One template node plus a few sources of variation replaces a whole wall of hardcoded prompt nodes, and it keeps your workflow readable instead of a knot of duplicated text.
How it works
Mechanically it's dead simple: string replacement. The template string is searched for the literal placeholders [a], [b], [c], and [d], and each is replaced with the value of the matching input. The four slots are optional inputs (each a multiline string), so you can use just [a] or all four. There's no escaping, no nesting, no conditionals - this is deliberately lightweight.
The choice of bracket syntax is the smart part for ComfyUI: [a]..[d] won't collide with the square brackets some models use for emphasis syntax, and the pack's README notes it plays well with JSON templates. If you ever need more than four slots, the same pack ships Text Template Extended with eight ([a] through [h]).
Inputs and output
template- the multiline template with[placeholder]syntax. Default "The [a] walks in the [b]".a,b,c,d- optional multiline values for each placeholder. Each is forced to an input (you can also type directly into them).
Output:
output- the assembled STRING, ready to feed a CLIPTextEncode or anything else that eats a prompt.
Installing it
Part of ComfyUI-nhknodes:
cd ComfyUI/custom_nodes && git clone https://github.com/Enashka/ComfyUI-nhknodes
restart, or "NHK Nodes" from ComfyUI Manager. No extra dependencies.
Pair it with the pack's Cycling Switch
The natural companion here is the pack's own Cycling Switch. Feed three different subject descriptions into slots, run a cycling switch over the [a] value, and you get a "rotate through these subjects every N images" loop with one template node - exactly the batch-variation workflow people ask for on r/comfyui. The limitation to keep in mind: empty slots replace with empty strings, so a missing value just vanishes from the template rather than erroring. That's usually what you want, but it means "the walks in the" is a silent failure if you forget to connect a slot. Check your template after first wiring, and you'll be fine.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| template | STRING | The [a] walks in the [b] | Template text with [placeholder] syntax. Placeholders: [a] [b] [c] [d] |
| aopt | STRING | (optional) Value for [a] placeholder | |
| bopt | STRING | (optional) Value for [b] placeholder | |
| copt | STRING | (optional) Value for [c] placeholder | |
| dopt | STRING | (optional) Value for [d] placeholder |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| output | STRING | β |