Nodes/ComfyUI_EmAySee_CustomNodes/EmAySee Var Text Replacer
ComfyUI Node

EmAySee Var Text Replacer

%var% placeholders

By EmAySee·Created about a year ago·Updated 4 months ago· 2
EmAySee Var Text Replacer
    • replaced_text
    main_textThis is %var1%, that is %var2%, and here is %var3%. We also have %var4%, %var5%, %var6%, %var7%, %var8%, %var9%, and finally %var10%.
    var1Variable 1
    var2Variable 2
    var3Variable 3
    var4Variable 4
    var5Variable 5
    var6Variable 6
    var7Variable 7
    var8Variable 8
    var9Variable 9
    var10Variable 10

    This is the sleeper hit of the pack. EmAySee Var Text Replacer is the generic version of the "fill in the blanks" prompt pattern: you write a template with placeholders like %var1%, wire in up to ten string values, and get one assembled string out. No AI, no regex, no API - just text substitution, and that's exactly what makes it reliable.

    Here's the setup. You get a multiline main_text field where you write your template - the default is a demo string showing off all ten placeholders - plus ten string inputs, var1 through var10. The node replaces every occurrence of %var1% with the value of var1, %var2% with var2, and so on, then hands you the finished text as a single replaced_text output.

    The mechanics are dead simple under the hood: ten str.replace() calls, in order. Which means a few things worth knowing:

    • Every occurrence gets replaced. Put %var1% in your template three times and all three get the value. That's the behavior you want from a template engine.
    • It's literal, not pattern-matching. There's no %var11% support, no escaping, no nested placeholders. If a placeholder doesn't match one of the ten exactly, it stays in the output untouched - which doubles as a handy "did I typo this?" signal.
    • Empty variables just vanish. Wire in an empty string and the placeholder disappears cleanly rather than leaving junk behind.

    Where this earns its keep is dynamic prompting. The classic setup: pipe var1 from a string selector, var2 from a date-time node, var3 from some other node's output, and build a prompt template that reads like a sentence instead of a pile of concatenated nodes. It's the same idea as the pack's own body-attribute nodes, but general - you can template prompts, file naming strings, or anything else that's text. If your prompt-engineering style is "write the sentence once, swap the subjects," this node is the swap mechanism.

    A note on where it lives: the node's category is EmAySee_Text (with an underscore), while most of the pack's text nodes use EmAySee/Text (with a slash). They're different menu groups, so if you search the node menu and it isn't where you expected, look under the underscore version.

    How to install

    Part of the shared pack install:

    cd ComfyUI/custom_nodes
    git clone https://github.com/EmAySee/ComfyUI_EmAySee_CustomNodes
    

    Restart ComfyUI, or just search ComfyUI_EmAySee_CustomNodes in ComfyUI Manager. No requirements.txt, no models, no heavy dependencies - this is plain Python string handling.

    Where people trip up

    • The defaults are demo values. The default main_text is the "This is %var1%..." example, and var1–var10 default to "Variable 1" etc. If you load the node and test it without touching anything, you'll get the demo output, not an empty string. Type over the defaults before judging it.
    • Typos in placeholders pass silently. Because unmatched placeholders stay in the output, a %Var1% with the wrong case won't error - it'll just show up in your prompt. Use the exact %var1%%var10% names.
    • The ten inputs are fixed. There's no way to add an eleventh. If you need more, chain a second VarTextReplacer - feed its replaced_text into the new node's main_text and keep going.

    Compared to the fancier prompt-formatting utilities out there, this one is refreshingly boring. That's the point: boring, predictable, and exactly what you need when a workflow keeps changing its mind about what goes in the sentence.

    CategoryEmAySee_Text

    Inputs (11)

    NameTypeDefaultDescription
    main_textSTRINGThis is %var1%, that is %var2%, and here is %var3%. We also have %var4%, %var5%, %var6%, %var7%, %var8%, %var9%, and finally %var10%.
    var1STRINGVariable 1
    var2STRINGVariable 2
    var3STRINGVariable 3
    var4STRINGVariable 4
    var5STRINGVariable 5
    var6STRINGVariable 6
    var7STRINGVariable 7
    var8STRINGVariable 8
    var9STRINGVariable 9
    var10STRINGVariable 10

    Outputs (1)

    NameTypeDescription
    replaced_textSTRING