Nodes/ComfyUI-NynxzNodes/String Template Parser
ComfyUI Node

String Template Parser

A {{ placeholder }} replacer for prompts, filenames, and API payloads

By Nynxz·Created 9 months ago·Updated 2 months ago· 0
String Template Parser
    • result
    source_text
    variable_name
    replacement_text
    replacements_json
    default_for_missing
    replace_missing_with_defaultfalse

    String Template Parser is one of those glue nodes you don't miss until you need it: you give it text with {{ placeholders }} inside, and it swaps in the values you provide. That's the whole job - a string in, a string out. No API, no model, no API key. The name is a lie in the best way: it doesn't call anything, it just runs a regex and a bit of JSON parsing locally.

    Where does that fit in a workflow? Prompts, mostly. The classic pattern: keep one long, carefully tuned prompt template as a single text node, then swap a variable like the subject, the model name, or a LoRA trigger in per batch without hand-editing the whole block. It's equally handy for filename templates in save workflows, for building JSON payloads when you're scripting the API, or for that one friend who wants to run the same style prompt across a dozen seeds and only change a keyword each time. If you've ever built the same thing with a pile of Text Concatenate nodes, you'll appreciate how much simpler this reads.

    How it works

    The node scans source_text for placeholders of the form {{ name }} and substitutes them from a mapping. There are two ways to build the mapping:

    • Single replacement: set variable_name and replacement_text. Any placeholder matching that name gets the text.
    • Batch replacement: set replacements_json to a JSON object like {"model": "flux-dev", "steps": "28"} and it applies to every placeholder in one pass. If both are provided, the JSON wins and the single pair only fills in names the JSON didn't cover.

    The interesting edge case is what happens to placeholders nobody supplied. By default they're left untouched - the {{ name }} stays literal in the output. Flip replace_missing_with_default on and missing placeholders collapse to default_for_missing instead. That's handy when you're reusing one template across contexts where some variables don't apply.

    The inputs, quickly

    • source_text - the template.
    • variable_name / replacement_text - the single-pair replacement.
    • replacements_json - multiline field for the batch JSON object.
    • default_for_missing / replace_missing_with_default - the fallback behavior.

    One output, result, a plain STRING. Wire it into a save-text node, a prompt input, or anything else that eats a string. Note the placeholder grammar is strict-ish: names can use letters, digits, underscores, and hyphens, with spaces inside the braces allowed.

    Common gotchas

    • Bad JSON is silently ignored. If replacements_json doesn't parse, the node doesn't error - it just drops the mapping and keeps going. If your placeholders come back unreplaced, check the JSON first.
    • Unmatched placeholders stay literal. Expect {{ name }} to survive in the output unless replace_missing_with_default is on. That's a feature, but it surprises people who expect an error.
    • It's a string node. It can't touch numbers, images, or latents. Convert anything you need into text upstream.

    Install

    It's part of Nynxz/ComfyUI-NynxzNodes, on the Comfy Registry under publisher nynxz. ComfyUI Manager: search "Nynxz" or "ComfyUI-NynxzNodes", install, restart. Manual:

    cd ComfyUI/custom_nodes
    git clone https://github.com/Nynxz/ComfyUI-NynxzNodes
    

    Then restart. Zero extra dependencies - the implementation is stdlib re and json only, so nothing to pip-install and nothing to download. The pack targets the newer comfy_api.latest API, so if the node doesn't show up after restart, update ComfyUI first.

    CategoryNynxz

    Inputs (6)

    NameTypeDefaultDescription
    source_textSTRING
    variable_nameSTRING
    replacement_textSTRING
    replacements_jsonSTRING
    default_for_missingSTRING
    replace_missing_with_defaultBOOLEANfalse

    Outputs (1)

    NameTypeDescription
    resultSTRING