Nodes/Chaser's Custom Nodes/Load Template File
ComfyUI Node

Load Template File

Keep your prompt templates in .j2 files instead of pasting them everywhere

By chaserhkj·Created about a year ago·Updated 12 months ago· 0
Load Template File
  • tmpl_dict
  • TMPL_DICT
template_file

Template File Loader is the file-backed way to get named templates into this pack's templating system. Pick a .j2, .jinja, or .txt file from the dropdown and it comes out as a TMPL_DICT - one entry whose name is the filename without the extension, ready to feed Prompt Template or chain into Register Template.

Same placement gotcha as the YAML loader: the dropdown scans the pack's own directory (ComfyUI/custom_nodes/ComfyUI-Chaser-nodes/), not ComfyUI's input folder. That's where the pack's own common.j2 lives, and it's the only template file the pack ships with. If you see the dropdown listing common.j2 and requirements.txt (which matches .txt), you're looking at the pack folder - yes, requirements.txt qualifies and will show up, harmless as it is.

# drop your own templates here, then restart ComfyUI
cp my-prompt.j2 ComfyUI/custom_nodes/ComfyUI-Chaser-nodes/

The file list is computed at class load, so new files need a restart to appear.

The one file that ships with it is worth studying. common.j2 is a Jinja macro file the author uses for anime/illustration prompting - it defines il_pos_prefix, il_pos_postfix, and il_neg macros that emit the kind of quality-tag boilerplate people stack on Illustrious-lineage models: masterpiece, best quality, amazing quality, 4k, very aesthetic, high resolution and so on, with a reality flag to swap in photorealistic variants. Load it, import it from a Prompt Template, and you inherit the author's prompt discipline without copying the tags by hand.

What you actually set. The template_file dropdown is the one thing you choose; an optional tmpl_dict input appends the loaded template to an existing dict instead of starting a new one. Output is a single TMPL_DICT.

Gotchas:

  • The template name is derived from the filename, so my-prompt.j2 becomes key my-prompt. Reference that exact name in your templates' include/import statements.
  • It's a loader, not a registry - it reads the file at run time, so edits to the .j2 apply on the next run without a restart. That's actually the nice part of the file approach: tweak a prompt in the file, rerun.
  • If you do git pull on the pack, common.j2 may change under you. Your own files survive (they're untracked), but a clean re-clone wipes them - back them up.

Install is the pack standard: ComfyUI Manager (search "Chaser's Custom Nodes") or:

cd ComfyUI/custom_nodes
git clone https://github.com/chaserhkj/ComfyUI-Chaser-nodes

then restart. No model downloads; jinja2, pyyaml, requests, sexpdata, and av install automatically. The README's "use them at your own risk" warning is aimed at workflows built around personal templates - know that going in.

CategoryChaser Custom Nodes

Inputs (2)

NameTypeDefaultDescription
template_fileCOMBO2 options: common.j2, requirements.txt
tmpl_dictoptTMPL_DICT

Outputs (1)

NameTypeDescription
TMPL_DICTTMPL_DICT