Nodes/Template Vars/Template Variable
ComfyUI Node

Template Variable

The one that turns a text box into a named slot for your prompt

By boobkake22·Created 3 months ago·Updated 2 months ago· 0
Template Variable
    • variables
    namecharacter
    value

    The Template Variable node is where a named value is born in this pack. You give it a name and a value, and it hands back a one-entry TEMPLATE_VARS map you can wire into a merge or an Apply node. It's the simplest possible thing in the pack - a dictionary with one key-value pair in node form - and that simplicity is the whole design.

    This is the node you reach for when the value is something you want to type and tweak right there in the node. Your location value, your character1 description, a style snippet you reuse across multiple templates. One node per variable, name in the top box, value in the multiline box below. That's it.

    Why it exists

    The pack's founding argument is that ComfyUI variables shouldn't live in a global dictionary or a JSON file you edit by hand. Instead, variables are ordinary node outputs that travel over wires, scoped to the workflow you can see. Template Variable is the "define a literal" part of that idea - the counterpart to Template Variable From String, which takes its value from a connected wire instead of a widget.

    When you'd pick this one over From String: any time the value is hand-typed and doesn't come from another node. A character sheet you're still editing, a negative-prompt fragment you want to swap across runs. If the value already exists elsewhere in the graph - a text node, a filename node, a prompt-generator output - use From String instead and save yourself the double entry.

    The inputs that matter

    • name - the variable name, e.g. character1. Single line. It's also the placeholder you'll use in your template: name location means {location} in an Apply Template Variables node.
    • value - the replacement text, multiline. This is the part you'll be editing constantly.

    Both get whitespace-trimmed automatically, and names are validated: they must start with a letter or underscore, then letters, numbers, underscores, and hyphens only. character_1 is fine; 1character or char 1 will error. That rule is shared across the whole pack, so it's worth internalizing once.

    The output is one variables (TEMPLATE_VARS) socket. It's a custom wire type, so it only plugs into other Template Vars nodes - but because the pack's Apply and CLIP nodes also take a single map, you can technically feed a one-variable map straight in if you only have one slot to fill.

    Realistic usage

    You almost never use this node alone. The typical shape is: several Template Variable nodes feeding a Merge Template Variables, which feeds Apply Template Variables or the CLIP Text Encode node. The README's example does exactly that - character1, character2, location as separate nodes, merged, then applied to This is {character1} and {character2} standing in {location}.

    The mildly annoying part of that pattern is node sprawl - three variables, three boxes. If you're defining a lot of variables at once from already-existing strings, the pack's Template Variables From Strings node collapses the whole thing into one node with a names list. But for a couple of hand-typed values, one box per variable is honestly clearer than anything fancier, and it's the version that's easiest to explain to someone else reading your workflow later.

    Installation

    Zero dependencies, zero model downloads - it's one of six nodes in boobkake22/ComfyUI-TemplateVars. Install via ComfyUI Manager (search "Template Vars") or cd ComfyUI/custom_nodes && git clone https://github.com/boobkake22/ComfyUI-TemplateVars, then restart. The nodes live under Template Vars.

    One gotcha if you're on a newer ComfyUI: this node's value widget disables dynamic prompt expansion on purpose, so {} characters in your value are treated as literal text, not as wildcards ComfyUI would normally try to expand. If something you typed as a placeholder isn't being substituted downstream, it's usually a name mismatch - check for a trailing space or a hyphen where an underscore should be.

    CategoryTemplate Vars

    Inputs (2)

    NameTypeDefaultDescription
    nameSTRINGcharacter
    valueSTRING

    Outputs (1)

    NameTypeDescription
    variablesTEMPLATE_VARS