Skip to content

Docs: How to share an existing JinjaX catalog with JinjaxRenderer #13

@fsecada01

Description

@fsecada01

Problem

Most FastAPI + JinjaX projects already initialise a Catalog instance at startup — often shared with Jinja2Templates so that standard page templates and JinjaX components coexist in the same environment with custom filters, globals, and extensions already registered:

# consts.py (typical project setup)
templates = Jinja2Templates(directory="templates")
templates.env.add_extension(JinjaX)
catalog = Catalog(jinja_env=templates.env)
catalog.add_folder("templates/components")
catalog.jinja_env.globals["url_for"] = ...

The README example creates a fresh Catalog in isolation:

catalog = Catalog()
catalog.add_folder(templates_dir)
renderer = JinjaxRenderer(catalog)
Component.renderer = renderer

This silently misses all existing filters, globals, and extensions — component templates render incorrectly (missing url_for, custom filters, etc.).

Request

Add a section to the README / docs explaining:

  1. Pass your existing catalog directly: Component.renderer = JinjaxRenderer(existing_catalog)
  2. Why creating a new catalog loses context (different jinja_env)
  3. If using Jinja2Templates, show the pattern for sharing the env

What works

# In consts.py — after existing catalog setup:
from component_framework.adapters.jinjax_renderer import JinjaxRenderer
from component_framework.core.component import Component
Component.renderer = JinjaxRenderer(catalog)   # ← share the existing catalog

This gives component templates full access to all custom filters and globals.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions