Nodes/Qaz Tools/Jinja2 Template
ComfyUI Node

Jinja2 Template

Jinja2 templating, minus the variables

By qazwsxedc121·Created 3 months ago·Updated 3 months ago· 1
Jinja2 Template
    • STRING
    text
    autorefreshNo

    Jinja2 Template renders your text field as a Jinja2 template and hands the result back as a STRING. It's the most surprising node in the Qaz Tools pack, because of what it can't do: the template is rendered with an empty context. template.render() is called with no arguments, so no other node's outputs get passed in as template variables. {{ my_var }} renders as a blank string, not an error - Jinja2's default Undefined prints nothing.

    So this is not the "feed outputs from ten nodes into a template" node that name might suggest. It's for self-contained logic inside a single field. Think loops, conditionals, filters, and string math that build a prompt without any external inputs:

    {% for i in range(3) %}
    portrait of a cat, expression {{ 'serious' if i == 1 else 'playful' }}
    {% endfor %}
    

    Or comma-join a generated list with {{ items|join(', ') }}. If you want to produce a programmatically-structured prompt from static pieces, or stamp out a small family of similar prompts, it does that cleanly. Just don't expect to inject your LoRA name or the current date - there's no way in.

    The inputs that matter

    • text - the template itself, multiline.
    • autorefresh - this is the one node in the pack where it does something. With "No" (default) the node caches and only re-renders when the text changes; with "Yes" it re-renders on every execution (IS_CHANGED returns NaN).

    Output is a single STRING - wire it into a CLIP Text Encode or into QazOutput to inspect the rendered result.

    The silent-pass-through gotcha

    This is the trap, and it's straight from the source: any exception - jinja2 not installed, or a template syntax error - is caught and the node returns your text unchanged. A broken {% for %} won't fail the graph, it'll just pass through as literal text and you'll wonder why your prompt contains the words "for i in range". If your output looks un-rendered, check two things: is the template valid Jinja2, and is jinja2 importable in the same Python that runs ComfyUI? The dependency is lazy - the node works without it, it just silently does nothing.

    Installing Qaz Tools

    Same as every node in this pack: Qaz Tools is a small personal toolkit from qazwsxedc121, no models, no heavy requirements. Install, then restart ComfyUI:

    cd ComfyUI/custom_nodes
    git clone https://github.com/qazwsxedc121/comfyui-qaz-tools
    

    Or in ComfyUI Manager, search "Qaz Tools" / paste the repo URL under Install via Git URL.

    Given the empty-context constraint and the silent fallback, this node is best treated as a lightweight prompt-builder, not a general templating engine. For injecting other nodes' values into text, you'd be happier with a pack that passes a context - but if the job is "loop inside one box," it's genuinely the smallest tool that does it.

    CategoryQaz Tools

    Inputs (2)

    NameTypeDefaultDescription
    textSTRING
    autorefreshCOMBONo2 options: Yes, No

    Outputs (1)

    NameTypeDescription
    STRINGSTRING