Nodes/Template Vars/Merge Template Variables
ComfyUI Node

Merge Template Variables

Combine your variable maps, and know which one wins when names collide

By boobkake22·Created 3 months ago·Updated 2 months ago· 0
Merge Template Variables
  • variables
  • variables

Merge Template Variables is the pack's glue node: it takes multiple TEMPLATE_VARS maps and combines them into one. That's the entire job, but "combine" hides the one behavior you actually need to understand, and it's the difference between this node being useful and it quietly wrecking your prompt.

What it does

Every creator node in the pack - Template Variable, From String, From Strings - emits a one-or-more-entry TEMPLATE_VARS map. When your workflow has several of those, Merge bundles them into a single map you can feed to Apply Template Variables or the CLIP Text Encode node. The README's example workflow builds character1, character2, and location as three separate nodes, merges them, then applies the merged map to the template. Without the merge you'd need to patch variables into your Apply node one at a time, which the pack deliberately doesn't offer.

The input is a single variables socket that's dynamic on current ComfyUI: start with one connected map and grow as you connect more, up to 100. On older builds it's ten fixed inputs (variables_1 through variables_10). The output is one variables (TEMPLATE_VARS) map, ready to wire anywhere a single map is expected.

The behavior that matters: later wins

When two input maps contain the same variable name, the merge is not a merge in the "blend them" sense - it's a last-writer-wins overwrite. The README says it plainly: later inputs override earlier inputs with the same name. What "later" means is the order of the connected sockets, so the map plugged into the highest input index wins any collision.

This is a feature, not a bug. It lets you set a default map (character descriptions, shared style tags) and then override individual values with a second, higher-connected map - a batch overrides a base, a per-run override wins over a saved default. But it's also the classic silent-failure trap: connect two maps that both define location, and one of them stops mattering entirely with no error and no visual hint. If a variable you know you set is rendering wrong, suspect a merge collision before anything else.

Since it's the same mechanism whether you use one creator node or ten, there's also no real cost to keeping your maps separate and merging late in the graph - that separation is exactly what lets you reuse one map across several templates in the same workflow.

When you might skip it

If you're building all your variables in one Template Variables From Strings node, the output is already a full map - no merge needed, the README's own example connects that node straight into the CLIP encoder. Merge only earns its place when variables come from multiple sources: a hand-typed set plus a wire-fed set, or a shared "defaults" map you drop into many workflows. Use it then, and use it deliberately.

Installation

One of six nodes in boobkake22/ComfyUI-TemplateVars - no dependencies, no model files, nothing to download past the repo itself. Install via ComfyUI Manager (search "Template Vars") or cd ComfyUI/custom_nodes && git clone https://github.com/boobkake22/ComfyUI-TemplateVars, then restart. The nodes sit under Template Vars.

If your merge ever needs to be order-independent, the answer is simpler than it sounds: don't rely on overrides at all, keep variable names unique across your maps, and let the merge be a pure union. That's the setup that never bites you.

CategoryTemplate Vars

Inputs (1)

NameTypeDefaultDescription
variablesCOMFY_AUTOGROW_V3

Outputs (1)

NameTypeDescription
variablesTEMPLATE_VARS