3683a610e2a7107664df67f07b40bb02dd3cdf18
"Do one thing and do it well." — Peter H. Salus / Doug McIlroy, core Unix principle
"Simple is better than complex." — Zen of Python
String Constructor (Text-Formatting) nodes
There's already a plenty of string-formatting nodes for ComfyUI. But this node pack takes a different approach:
- First, you prepare a dictionary of named sub-strings (chunks of text with assigned keyword/tag to reference them with).
- Then, right before
CLIP Text Encode, you construct a final prompt fom this dictionary of available parts, connected as a single input. The compilation itself is done using python's string formatting syntax... Don't panic! You don't need to be a programmer - just look below for a quick introduction. - Unlike many other (giant uber-mega) node packs, this one strictly adheres to the modular philosophy: it's minimal and self-sufficient.
Syntax
For those who are unfamiliar with python's string formatting, the rules are very simple:
- You need to name (set tags/keys for) your sub-strings the same way python variables are named: only ASCII letters, digits and underscore are allowed + the name can't start with a digit. So:
- ✅
valid_name,other_valid_name,YetAnother_ValidName,name3. - ❌
wrong name with spaces,wrong-name.with:punctuation,3name.
- ✅
- Then, you simply put your
{substring_name}inside curly braces (no spaces between) in the formatting template - and voila! This pattern will be replaced with the actual sub-string.
Note
For advanced users: Internally, a built-in
str.format()is called with keyword arguments fromstr_dict, which is literally just a dict... though, an immutable one. So any formatting patterns are available (like{float_value:.3f}) +Add ANY to Format-Dictnode is there for exactly that.
Languages
Python
100%
