String Format
A tiny template language for prompts, filenames, and JSON snippets
- input_1
- input_2
- input_3
- input_4
- input_5
- input_6
- input_7
- input_8
- input_9
- input_10
- input_11
- input_12
- input_13
- input_14
- input_15
- input_16
- string
ComfyUI's string plumbing is the least-glamorous part of the graph and the one everyone ends up needing. String Format from the Diztraido pack is a template engine for strings: you write a template with {1}, {2} placeholders, set how many inputs you want, and it substitutes values from sockets that accept strings, ints, floats, or booleans. The interesting part is the extras: a {1?} placeholder deletes the whole line when that input is empty, and there's a real @if/@else/@endif conditional block system with comparison operators. It's the node you reach for when you're building a filename, an API payload, or a prompt that changes shape depending on what's actually connected.
The default template is literally File_{1}_teste_{2} - the author is Brazilian and it shows, but that's a fine starting point for "filename with a couple of variables" workflows.
How it works
The backend is a small template interpreter. Positional {1}…{16} substitute in order; the ? suffix ({1?}) is the clever bit - if that input is None, empty, or whitespace, the entire physical line containing it is removed, which is perfect for optional chunks like a style tag line. Numbers and booleans are preserved as values (a numeric 0 or false is not treated as empty). Whole-line @if {1} / @else / @endif blocks work with the same operators as inline expressions (==, !=, <, <=, >, >=, !, &&, ||, parentheses), nestable, and can contain raw JSON without escaping. A few structural niceties: literal JSON braces are fine as-is, {{ escapes a placeholder-looking sequence, and when an optional line or block is removed, trailing commas before } or ] get cleaned automatically so your generated JSON stays valid. Lines starting with # are dropped. The frontend extension adds/removes input sockets as you change input_count.
The inputs that matter
template- the multiline template with placeholders and conditionals.input_count- 0 to 16, how manyinput_Nsockets exist. Set this before wiring.single_line_output- normalize the output to a single line when on.
Optional input_1 … input_16 - wildcard sockets that accept any type.
Output: string (STRING), ready for a prompt encoder, filename prefix, or a Save Text node.
A quick example - this template:
portrait of {1}
@if {2}
, in the style of {2}
@endif
@if {3}
, {3}
@endif
with input_1 = "a woman", input_2 = "art deco", input_3 empty produces portrait of a woman, in the style of art deco - and if you later disconnect input_2, the middle line vanishes instead of leaving a dangling comma.
How to install
Part of Diztraido Nodes. ComfyUI Manager → search "Diztraido Nodes" → install diztraido-nodes → restart. Or:
cd ComfyUI/custom_nodes
git clone https://github.com/jadervasque/ComyUI-Diztraido.git
Restart and it's under the Diztraido utils category. No dependencies or models.
Common issues
The usual stumbles: forgetting that input_count gates which sockets exist (the template can reference {5} all day, but if input_count is 2, there's no input_5 socket), and the difference between {1} and {1?} - use the plain form when you always want the value, the ? form when the line should disappear if empty. Also, single_line_output normalizes everything to one line; if you're building a multi-line prompt and toggle it by mistake, you'll wonder where your paragraphs went.
Inputs (19)
| Name | Type | Default | Description |
|---|---|---|---|
| template | STRING | File_{1}_teste_{2} | — |
| input_count | INT | 20–16 | — |
| single_line_output | BOOLEAN | false | — |
| input_1opt | * | — | |
| input_2opt | * | — | |
| input_3opt | * | — | |
| input_4opt | * | — | |
| input_5opt | * | — | |
| input_6opt | * | — | |
| input_7opt | * | — | |
| input_8opt | * | — | |
| input_9opt | * | — | |
| input_10opt | * | — | |
| input_11opt | * | — | |
| input_12opt | * | — | |
| input_13opt | * | — | |
| input_14opt | * | — | |
| input_15opt | * | — | |
| input_16opt | * | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| string | STRING | — |