String template
Mail-merge for prompts
- replacements
- ui_widget
- string
- string_list
Writing out ten near-identical prompts by hand, changing one or two words each time, is exactly the kind of repetitive text work a node should be doing for you instead. LF_StringTemplate is basically mail-merge for prompts: write the template once with placeholders, hand it a list of substitutions, and get every variation back without retyping the parts that don't change.
The template field is your multiline text with placeholders like {name} or {style} sitting wherever you want a substitution to land. replacements is a JSON value - a list of dictionaries, where each dictionary's keys match your placeholder names and each dictionary produces one filled-in result. Three dicts in the list means three results out. If you'd rather get just one instead of the full set, randomize (off by default) picks a single dictionary at random from the list, seeded by seed (default 42) for reproducibility. There's also use_regex_placeholders, which switches placeholder matching from the literal {name} style to a regex pattern like {\w+} - useful if your templates need more flexible matching than exact-name placeholders allow, though it's the more advanced option and most templates won't need it.
Two outputs: string, either your single randomized result or (when randomize is off) presumably the first/primary result, and string_list, every filled-in variation from the full replacements list. Feed string_list downstream if you want the full batch; use string if you just want one.
Since replacements needs to arrive as JSON, if you're typing it as plain text rather than constructing it elsewhere in your graph, pair this with LF_StringToJSON first to get it into the right type.
The combination worth remembering is this node plus LF_ImageListFromJSON: point both at the same replacements list, and you get a matched pair - one text variant per entry from this node, one placeholder canvas per entry from that one - without hand-counting anything or keeping two separate lists in sync yourself. It's a small pattern, but it's the kind of thing that saves real time once you're iterating on a batch of prompt variations rather than a single one.
Installing it. ComfyUI Manager: search "LF Nodes," install, restart. Manual: cd ComfyUI/custom_nodes && git clone https://github.com/lucafoscili/lf-nodes, then restart. Use that repo - comfyui-lf, comfy.icu's link, is the pack's archived original home; active development moved to lf-nodes. No models, no heavy dependencies.
Where people get tripped up. Placeholder names in your template have to match dictionary keys in replacements exactly, case included - a {Name} in your template won't pick up a name key in your JSON. Second, malformed JSON in replacements is the most common failure point generally in this pack, and this node is no exception - validate it (or build it through LF_StringToJSON first) rather than hand-typing a long list of dicts and hoping the syntax is right. And if you enable use_regex_placeholders without actually needing regex-style matching, you're adding complexity for nothing - stick with plain {name} placeholders unless your use case genuinely needs pattern matching.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| template | STRING | The string template with placeholders matching the keys of the input dictionaries (e.g.: {name}, {style}, etc.). | |
| replacements | JSON | [object Object] | A list of dictionaries for placeholders. Each dictionary is used for a separate result. |
| seedopt | INT | 42 | Seed to control the randomness of the shuffling. |
| randomizeopt | BOOLEAN | false | If true, randomly pick one dictionary from the replacements list. |
| use_regex_placeholdersopt | BOOLEAN | false | Enable regex placeholders like {\w+} for advanced templates. |
| ui_widgetopt | KUL_CODE | [object Object] | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| string | STRING | — |
| string_list | STRING | — |