ComfyUI Node

String Toggle

Flip whole prompt sections on and off without retyping a word

By uihp·Created 2 years ago·Updated about a year ago· 1
String Toggle
    • STRING
    separator,
    previous

    This is the node from the ComfyUI-String-Chain pack that's actually interesting. Where String Chain and String Concat join exactly two strings, String Toggle gives you a stack of text slots, each with its own on/off checkbox, and joins only the enabled ones into one STRING output. You build a prompt out of sections - subject, style, quality tags, lighting - and flip sections on and off to A/B them without deleting a single character.

    How it works

    How it works is where it earns its keep. The node starts with a previous wire-in input (same forceInput pattern as its siblings), a separator field (default ", "), and two buttons: Add and Remove. Click Add and the frontend JavaScript appends a divider line plus a toggle and a text box for one new "unit." Type a prompt fragment into any unit, and the Python join reads the units back out of the widget values, keeps the ones whose toggle is on, prepends previous if it has text, and joins everything with the separator. The output is a plain STRING that feeds CLIPTextEncode or any string consumer, so you can put the toggle right before your encoder and switch prompt styles between generations by clicking checkboxes.

    The dynamic units

    That dynamic-slot trick is borrowed from rgthree's playbook - the pack's common.py literally credits rgthree's AnyType/flexible-input machinery, the same pattern that lets Power Lora Loader stack arbitrary LoRAs. So the toggle accepts wires of any type, though it's clearly built for strings. Each unit's text and enabled state are saved into the workflow JSON, so reload the file later and your sections come back exactly as you left them.

    Gotchas

    Three things will bite you. First, enabled-but-empty units are still joined, so a toggled-on empty box produces doubled separators like ", , " in the middle of your prompt - disable empty units or remove them. Second, the node starts with no units at all; only Add, Remove, and the separator are there, so don't hunt for a missing text box - click Add. Third, and this is the real one: Toggle redefines the server node from the frontend via the beforeRegisterNodeDef override, which is precisely the pattern that broke under ComfyUI's Nodes 2.0 frontend rewrite. If you're on Nodes 2.0 and the Add button or toggles don't render, that's your culprit, and the standing community workaround is to keep Nodes 2.0 switched off.

    Install

    Install is trivial either way - ComfyUI Manager (search ComfyUI-String-Chain) or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/uihp/ComfyUI-String-Chain
    

    Restart. No dependencies, no model files, nothing to configure. The pack is young and quiet - one commit, an empty README, no reddit presence - but the Toggle is the genuinely useful node in it, and it's the one I'd reach for if I installed only one. Want the same thing with big multiline boxes for long prose prompts instead of single-line ones? That's the String Toggle (Multiline) variant in the same pack.

    Categoryutils

    Inputs (2)

    NameTypeDefaultDescription
    separatorSTRING,
    previousoptSTRING

    Outputs (1)

    NameTypeDescription
    STRINGSTRING