Text Switch Case
Pick a string based on a condition
- STRING
This is a switch statement for text, dropped into a node. You give it a list of case:value pairs, a condition to match on, and a fallback, and it returns the value whose case matches the condition. It's how you make a workflow branch on text without wiring up a tangle of logic nodes - one input decides which of several strings comes out.
Where it clicks is any workflow driven by a label. Say a request comes in tagged portrait, landscape, or product, and each needs a different prompt suffix, a different style string, or a different setting. Feed the tag in as the condition, list the responses as cases, and the node hands back the right one. Change the tag, get a different branch, same graph. For automated or template-y setups this is the difference between one flexible workflow and five near-identical ones.
How it works
You write the cases as lines of case<delimiter>value, one per line, with the delimiter defaulting to a colon. The node compares the condition string against each case; on a match, it returns that case's value. No match, and it returns default_value. Values can span multiple lines, so a single case can return a whole multi-line prompt, not just a word.
Inputs and outputs
Four required inputs:
switch_cases- the multiline list ofcase:valuepairs. This is the body of the switch.condition- the string to match against the cases. Usually wired in from upstream (a tag, a JSON field, a mode selector).default_value- what comes out when nothing matches. Set this to something safe; it's your fallback.delimiter- the separator between case and value, default:. Change it if your values themselves contain colons (URLs, timestamps), so the split doesn't land in the wrong place.
The output is a single STRING - the matched value, or the default.
Installing it
Ships with the ArtVenture pack. ComfyUI Manager: search comfyui-art-venture, install, restart. Or:
cd ComfyUI/custom_nodes
git clone https://github.com/sipherxyz/comfyui-art-venture
Restart ComfyUI. No downloads.
Common issues
Always getting the default. The condition isn't matching any case. Matching is literal, so watch for trailing spaces, capitalization, and invisible whitespace - a condition of Portrait with a trailing space won't match a case portrait. Trim the condition upstream and make the casing consistent.
The split landed wrong. Your values contain the delimiter. If a value is a URL like https://example.com, a colon delimiter splits at the wrong :. Switch delimiter to something that doesn't appear in your values, like => or |.
A multi-line value only returned its first line. Format the cases so the value continues on following lines as the pack's syntax expects; a case's value is allowed to run across multiple lines, so keep the continuation under the right case rather than starting a new case:value pair.
It feels like overkill for two options. For a straight either/or you might not need it. TextSwitchCase pays off once you have three, four, five branches - that's where hand-wiring conditionals gets ugly and a single switch node stays readable.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| switch_cases | STRING | — | |
| condition | STRING | — | |
| default_value | STRING | — | |
| delimiter | STRING | : | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| STRING | STRING | — |