π€ Text Case Switch
A switch statement for prompts, written in plain text
- Output
- Matched
Programmers have switch. ComfyUI has a dropdown and a prayer. Text Case Switch is the version that actually reads well: you write a table in a text box, one line per case, and the node picks the line whose left side matches the text coming in. It's the cleanest way in this pack to say "if the style selector says anime, prepend the anime prompt boilerplate."
How it works
Each line in Cases is split on the separator (| by default) into a case value and an output value, both stripped of surrounding whitespace. Then it walks the lines in order and returns the first one that matches. The Matched boolean tells you whether a real case hit or you fell through to Default Output - that's the difference between "it worked" and "silently used the fallback", and it's worth wiring to something visible while you're building.
Two switches change what "matches" means, and they're the whole usability story.
Ignore Case is on by default, which is what you want - nobody wants Anime to miss anime.
Match Substring is off by default, which means exact equality: the entire incoming text has to equal the case value. That's strict in a way people don't expect. If your selector node emits style: anime and your case says anime, nothing matches and you get the default. Either turn Match Substring on, or make the case value the exact string the upstream node produces.
Turning Match Substring on moves you to contains semantics - and then order matters, because it's first-match-wins. Put the specific cases first: anime realistic before anime, oil painting before painting. A substring table sorted carelessly is a table where the general case swallows the specific one.
The inputs and outputs that matter
Match Text is a forced input, so it must be wired - a Text node, a string parsed out of metadata, a value from a selector. Cases is the multiline table; the default value shows the format (photo | realistic photography on one line, anime | anime illustration style on the next) and it's the best documentation the node has. Default Output is what comes back when nothing matches. Separator defaults to | and can be changed if your outputs legitimately contain pipes - set it to => or ::: and the table stops fighting you. Ignore Case and Match Substring as above.
Two outputs: Output (the matched output string, or the default) and Matched (BOOLEAN). No index, no matched-case name - so if you need to know which case hit, the boolean won't tell you; match again downstream with Text Match, or encode the identity in the output text itself.
The canonical shape: a selector (a dropdown from a primitive, a parsed field, an LLM's classification) β Text Case Switch β CLIP Text Encode. The prompt boilerplate lives in the table where you can edit twelve variants without touching twelve nodes.
Lines without a separator are skipped silently, not flagged. That's forgiving until you spend ten minutes wondering why your third case never fires - usually a line you edited into anime anime style by accident.
How to install it
Part of Avaray/honda-nodes - ComfyUI Manager β Node Pack β search Honda Nodes β Install β restart. Manual:
cd ComfyUI/custom_nodes
git clone --depth 1 https://github.com/Avaray/honda-nodes.git
cd honda-nodes
python install.py
Stdlib only, so this node doesn't need the installer - but the same script fetches the jq and ime binaries for the JSON and metadata nodes. Requires ComfyUI 0.38.0+ (V3 schema API). No pip packages, no models.
Common issues
Always returns the default. Check Match Substring first: exact equality against a whole sentence is a common surprise. Then check for invisible differences - a trailing space on the incoming string, or a case value with a typo. Print both sides with Print to Console for one run and the mismatch is usually obvious.
The wrong case wins. Substring mode plus bad ordering. Most specific first.
Nothing in the table works at all. Either no line contains your separator (did you change Separator to something and then not use it in the table?), or the case values are empty - a line starting with | has no case value and is skipped.
Case values are trimmed but my output keeps its spacing. Intended: both sides are stripped, so you can't use leading spaces for indentation in the output. Build that with Text Concatenate if you need it.
A prompt with a | in it breaks the table. Change the separator. That's what the field is for.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| match_text | STRING | The base text to evaluate against the cases. | |
| cases | STRING | photo | realistic photography anime | anime illustration style | One case per line, in the format: case | output Example: photo | realistic photography anime | anime illustration style Lines without the separator are ignored. |
| default_output | STRING | Output returned if none of the cases match. | |
| separator | STRING | | | The character (or string) that divides the case value from its output value in each line. Default is '|'. |
| ignore_case | BOOLEAN | true | If enabled, ignores uppercase/lowercase differences when matching. |
| match_substring | BOOLEAN | false | If enabled, a case matches whenever it appears anywhere inside the Match Text (like 'contains'). If disabled, only exact matches count. |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| Output | STRING | β |
| Matched | BOOLEAN | β |