```
```text
page.css
layout.css
header.css
card.css
```
--------------------------------
### Initialize Jx Catalog with Flask
Source: https://jx.scaletti.dev/docs/working/flask
Basic setup for integrating Jx with a Flask application.
```python
from flask import Flask
from jx import Catalog
app = Flask(__name__)
catalog = Catalog(
"components/",
auto_reload=app.debug,
)
@app.route("/")
def home():
return catalog.render("pages/home.jinja")
```
--------------------------------
### View CLI output formats
Source: https://jx.scaletti.dev/docs/tools/check
Examples of default text output and structured JSON output for integration.
```bash
$ jx check myapp.setup:catalog
```
```text
✓ button.jinja - OK
✓ card.jinja - OK
✗ page.jinja:12 - Component 'Buton' used but not imported (did you mean 'Button'?)
✗ modal.jinja - Unknown import 'dialog.jinja' (did you mean 'dialogs/dialog.jinja'?)
4 components checked, 2 errors
```
```bash
$ jx check --format json myapp.setup:catalog
```
```json
{
"checked": 4,
"errors": [
{
"file": "page.jinja",
"abs_path": "/path/to/components/page.jinja",
"line": 12,
"message": "Component 'Buton' used but not imported",
"suggestion": "Button"
},
{
"file": "modal.jinja",
"abs_path": "/path/to/components/modal.jinja",
"line": null,
"message": "Unknown import 'dialog.jinja'",
"suggestion": "dialogs/dialog.jinja"
}
]
}
```
--------------------------------
### Add Blueprint-Specific Component Folders
Source: https://jx.scaletti.dev/docs/working/flask
Organize components by blueprint using prefixes. This example shows how to add shared components and blueprint-specific ones for 'blog' and 'admin'.
```python
from flask import Flask
from jx import Catalog
app = Flask(__name__)
catalog = Catalog(jinja_env=app.jinja_env, auto_reload=app.debug)
# Shared components
catalog.add_folder("components/")
# Blueprint-specific components
catalog.add_folder("blueprints/blog/components/", prefix="blog")
catalog.add_folder("blueprints/admin/components/", prefix="admin")
app.catalog = catalog
```
--------------------------------
### Dropdown Component Usage
Source: https://jx.scaletti.dev/docs/working/alpinejs
Example of how to use the `Dropdown` component, providing a label and content for the dropdown menu.
```html
ProfileSettingsLogout
```
--------------------------------
### add_package Method
Source: https://jx.scaletti.dev/docs/api/catalog
Registers components and optionally assets from an installed Python package.
```APIDOC
## POST /api/packages
### Description
Registers components and optionally assets from an installed Python package.
### Method
`add_package`
### Endpoint
`/api/packages`
### Parameters
#### Path Parameters
- **package_name** (str) - Required - The importable package name (e.g. "my_ui_kit").
#### Query Parameters
- **prefix** (str) - Required - Prefix for the components (e.g. "ui").
### Request Example
```python
catalog.add_package(package_name="my_ui_kit", prefix="ui")
```
### Response
#### Success Response (200)
- **None** - Indicates the package was successfully registered.
```
--------------------------------
### Usage of Conditional Layout Sections
Source: https://jx.scaletti.dev/docs/recipes/layouts
Examples demonstrating how to use the layout with conditional sections. The first example shows a full layout with a custom sidebar, while the second shows a minimal layout with both sidebar and footer disabled.
```jinja
{# Full layout with sidebar #}
{% fill sidebar %}
{% endfill %}
Dashboard
{# Minimal layout without sidebar #}
```
--------------------------------
### Configure Assets in JinjaX
Source: https://jx.scaletti.dev/docs/from-jinjax
JinjaX requires middleware setup and specific catalog rendering to manage assets.
```python
# Requires middleware setup
app.wsgi_app = catalog.get_middleware(
app.wsgi_app,
autorefresh=app.debug,
)
```
```jinja
{#css mypage.css #}
{#js mypage.js #}
{{ catalog.render_assets() }}
...
```
--------------------------------
### Standard Jinja Template Example
Source: https://jx.scaletti.dev/
A traditional, tightly coupled Jinja template using standard blocks and includes.
```jinja
{% extends "layout.html" %}
{% block title %}My title{% endblock %}
{% block body %}
{% for prod in products %}
{{ prod.title }}
{{ prod.price }}
{{ prod.description }}
{% endfor %}
{% with items=products %}
{% include "pagination.html" %}
{% endwith %}
{% endblock %}
```
--------------------------------
### Example collected asset structure
Source: https://jx.scaletti.dev/docs/installable
The directory structure generated after running collect_assets.
```text
static/pkg/
ui/
button.css
button.js
card.css
```
--------------------------------
### Setup htmx in Layout
Source: https://jx.scaletti.dev/docs/working/htmx
Include the htmx script in the base layout template to enable functionality across the application.
```jinja
{#def title #}
{{ title }}
{{ assets.render_css() }}
{{ content }}
{{ assets.render_js() }}
```
--------------------------------
### Complete Flask Application with Jx Catalog
Source: https://jx.scaletti.dev/docs/working/flask
A full Flask application example demonstrating Jx Catalog integration for component rendering, routing, authentication, and error handling.
```python
from flask import Flask, redirect, url_for, flash, session, g, request
from flask_wtf.csrf import CSRFProtect
from jx import Catalog
app = Flask(__name__)
app.secret_key = "your-secret-key"
csrf = CSRFProtect(app)
# Create catalog with Flask's Jinja environment
catalog = Catalog(
"components/",
jinja_env=app.jinja_env,
auto_reload=app.debug,
)
@app.before_request
def load_user():
user_id = session.get("user_id")
g.user = get_user_by_id(user_id) if user_id else None
@app.route("/")
def home():
return catalog.render("pages/home.jinja")
@app.route("/login", methods=["GET", "POST"])
def login():
if request.method == "POST":
user = authenticate(request.form["email"], request.form["password"])
if user:
session["user_id"] = user.id
flash("Welcome back!", "success")
return redirect(url_for("dashboard"))
flash("Invalid credentials", "error")
return catalog.render("pages/login.jinja")
@app.route("/dashboard")
def dashboard():
if not g.user:
return redirect(url_for("login"))
return catalog.render("pages/dashboard.jinja", user=g.user)
@app.errorhandler(404)
def not_found(e):
return catalog.render("errors/404.jinja"), 404
if __name__ == "__main__":
app.run(debug=True)
```
--------------------------------
### Relative Asset URLs
Source: https://jx.scaletti.dev/docs/assets
Example of declaring relative paths for assets.
```jinja
{#css card.css #}
{#js card.js #}
```
```html
```
--------------------------------
### Jinja2 Template for Static File Links
Source: https://jx.scaletti.dev/docs/working/fastapi
Example Jinja2 template demonstrating how to link to static assets like CSS and JavaScript using the `static` helper function.
```jinja
{#def title #}
{{ title }}
{% for css in assets.collect_css() %}
{% endfor %}
{{ content }}
{% for js in assets.collect_js() %}
{% endfor %}
```
--------------------------------
### Tabs Component Usage
Source: https://jx.scaletti.dev/docs/working/alpinejs
An example demonstrating how to assemble the `Tabs`, `Tab`, and `TabPanel` components to create a functional tabbed interface.
```html
OverviewFeaturesPricing
Overview
Overview content here.
Features
Features content here.
Pricing
Pricing content here.
```
--------------------------------
### Usage of Nested App Layout
Source: https://jx.scaletti.dev/docs/recipes/layouts
Example of how to use the 'app.jinja' layout. It imports the layout and passes a title, rendering the main content within the app structure.
```jinja
{#import "layouts/app.jinja" as App #}
Dashboard
```
--------------------------------
### Jinja2 Template Usage with Prefixed Components
Source: https://jx.scaletti.dev/docs/working/django
Example Jinja2 template demonstrating how to import and use components from different apps using their prefixes. Assumes `Layout`, `PostCard`, and `ProductCard` components are available.
```jinja
{#import "layout.jinja" as Layout #}
{#import "@blog/post-card.jinja" as PostCard #}
{#import "@shop/product-card.jinja" as ProductCard #}
Latest Posts
{% for post in posts %}
{% endfor %}
Featured Products
{% for product in products %}
{% endfor %}
```
--------------------------------
### Home Page using Basic Layout
Source: https://jx.scaletti.dev/docs/recipes/layouts
An example of a home page Jinja template that imports and uses the basic layout component, providing a title and content.
```jinja
{#import "../layout.jinja" as Layout #}
Welcome!
This is the home page.
```
--------------------------------
### Example of Component Instantiation with Attributes
Source: https://jx.scaletti.dev/docs/attrs
This shows a component being used with several attributes. 'text' is a defined argument, while 'id', 'disabled', and 'data-action' are extra attributes that will be collected by the attrs object.
```html
```
--------------------------------
### Usage of Blueprint-Specific Components in Templates
Source: https://jx.scaletti.dev/docs/working/flask
Import and use blueprint-specific components within your templates. This example shows how to import and render 'post-card' components in blog templates.
```jinja
{#import "@blog/post-card.jinja" as PostCard #}
{% for post in posts %}
{% endfor %}
```
--------------------------------
### Add Package to Catalog
Source: https://jx.scaletti.dev/docs/api/catalog
Registers components and assets from an installed Python package with an optional prefix.
```python
add_package(
package_name: str,
*,
prefix: str
) -> None
```
--------------------------------
### Create a Blueprint-Specific Jinja Component
Source: https://jx.scaletti.dev/docs/working/flask
Define a Jinja component for a specific blueprint. This example creates a 'post-card' component for the 'blog' blueprint.
```jinja
{#import "card.jinja" as Card #}
{#def post #}
```
--------------------------------
### Modal Component Usage
Source: https://jx.scaletti.dev/docs/working/alpinejs
Example of using the `Modal` component, defining trigger, title, content, and footer slots. Also shows how to trigger the modal from another element.
```html
{% fill trigger %}
{% endfill %}
Are you sure you want to delete this item?
{% fill footer %}
{% endfill %}
{# Or trigger from elsewhere #}
```
--------------------------------
### Define a Jinja Component
Source: https://jx.scaletti.dev/docs/quickstart
Create a Jinja template for a reusable component. This example defines a 'card' component that accepts 'title', 'content', and 'url' as parameters.
```jinja
{#def title, url #}
```
--------------------------------
### Button Component Usage
Source: https://jx.scaletti.dev/docs/attrs
Example of how to use the Button component, passing custom attributes like `text`, `variant`, `id`, and `disabled`.
```html
```
--------------------------------
### Best Practice: Document Expected Attributes
Source: https://jx.scaletti.dev/docs/attrs
Shows how to document expected attributes for a component using a comment, guiding users on common attributes like `class`, `id`, `disabled`, and `data-*`.
```jinja
{#def text #}
{# Common attrs: class, id, disabled, data-* #}
```
--------------------------------
### Catalog Initialization with Folder
Source: https://jx.scaletti.dev/docs/catalog
Demonstrates equivalent ways to initialize a Catalog with a component folder.
```python
# These are equivalent:
catalog = Catalog("components/")
catalog = Catalog()
catalog.add_folder("components/")
```
--------------------------------
### Usage of Nested Auth Layout
Source: https://jx.scaletti.dev/docs/recipes/layouts
Example of how to use the 'auth.jinja' layout. It imports the layout and passes a title, rendering the form content within the authentication card structure.
```jinja
{#import "layouts/auth.jinja" as Auth #}
Sign In
```
--------------------------------
### Use Jx Catalog in Django Views
Source: https://jx.scaletti.dev/docs/working/django
Render Jx templates using the catalog in Django views. This example shows rendering a home page and a product list page, passing data as needed.
```python
from django.http import HttpResponse
from myproject.components import catalog
def home(request):
return HttpResponse(catalog.render("pages/home.jinja"))
def product_list(request):
products = Product.objects.all()
return HttpResponse(
catalog.render("pages/products.jinja", products=products)
)
```
--------------------------------
### Component Usage with Extra Attributes
Source: https://jx.scaletti.dev/docs/attrs
An example of how to instantiate a component, passing declared arguments and additional attributes that will be handled by the attrs object. Here, 'title' is a declared argument, while 'class', 'id', and 'data-index' are collected as attrs.
```html
```
--------------------------------
### About Page using Navigation Highlighting Layout
Source: https://jx.scaletti.dev/docs/recipes/layouts
An example of an 'about' page that uses the layout with navigation highlighting. It passes 'about' as the 'current_page' to ensure the 'About' link is marked as active.
```jinja
{#import "layout.jinja" as Layout #}
About Us
```
--------------------------------
### Get All Attributes as Dictionary
Source: https://jx.scaletti.dev/docs/api/attrs
Access the 'as_dict' property to get an ordered dictionary of all attributes and properties, sorted by name.
```python
attrs = Attrs({
"class": "lorem ipsum",
"data_test": True,
"hidden": True,
"aria_label": "hello",
"id": "world",
})
attrs.as_dict
```
```python
{
"aria_label": "hello",
"class": "lorem ipsum",
"id": "world",
"data_test": True,
"hidden": True
}
```
--------------------------------
### Custom Render Loop for Static Files
Source: https://jx.scaletti.dev/docs/working/flask
Implement a custom render loop to generate links for static CSS files using `url_for`. This example is within a layout Jinja component.
```jinja
{% for css_file in assets.collect_css() %}
{% endfor %}
```
--------------------------------
### Define package entry points
Source: https://jx.scaletti.dev/docs/installable
Expose component and asset paths in the package's __init__.py file.
```python
from pathlib import Path
JX_COMPONENTS = Path(__file__).parent / "components"
JX_ASSETS = Path(__file__).parent / "assets"
```
--------------------------------
### Initialize JX Component Catalog
Source: https://jx.scaletti.dev/docs/working/django
Sets up the JX Catalog using the configured Jinja2 engine and registers a components folder.
```python
from django.conf import settings
from django.template import engines
from jx import Catalog
_jinja2_env = engines["jinja2"].env
catalog = Catalog(
jinja_env=_jinja2_env,
auto_reload=settings.DEBUG,
)
catalog.add_folder(settings.BASE_DIR / "components")
```
--------------------------------
### Get component data
Source: https://jx.scaletti.dev/docs/api/catalog
Retrieves component data from the cache, re-processing if the file has been updated.
```python
get_component_data(
relpath: str
) -> jx.catalog.CData
```
--------------------------------
### Create a Jx Catalog
Source: https://jx.scaletti.dev/docs/quickstart
Initialize a Jx Catalog instance pointing to the directory where your components will be stored.
```python
from jx import Catalog
catalog = Catalog("components/")
```
--------------------------------
### Catalog Constructor
Source: https://jx.scaletti.dev/docs/api/catalog
Initializes a new Catalog instance. It can scan a folder for components and accept various configurations for Jinja rendering and asset resolution.
```APIDOC
## Catalog Constructor
### Description
Initializes a new Catalog instance. It can scan a folder for components and accept various configurations for Jinja rendering and asset resolution.
### Method
`Catalog`
### Parameters
#### Path Parameters
- **folder** (str | pathlib._local.Path | None) - Optional - Folder path to scan for components.
#### Keyword Parameters
- **jinja_env** (jinja2.environment.Environment | None) - Optional Jinja2 environment to use for rendering.
- **extensions** (list | None) - Optional extra Jinja2 extensions to add to the environment.
- **filters** (dict[str, typing.Any] | None) - Optional extra Jinja2 filters to add to the environment.
- **tests** (dict[str, typing.Any] | None) - Optional extra Jinja2 tests to add to the environment.
- **auto_reload** (bool) - Default: `True`. Whether to check the last-modified time of component files and automatically re-process them if they change.
- **asset_resolver** (collections.abc.Callable[[str, str], str] | None) - Optional callable that transforms asset URLs for components.
- **globals** (Any) - Variables to make available to all components by default.
### Request Example
```python
from pathlib import Path
catalog = Catalog(folder=Path("/path/to/components"), auto_reload=False)
```
### Response
#### Success Response (200)
- **None** - Initializes the Catalog object.
```
--------------------------------
### Catalog Constructor Options
Source: https://jx.scaletti.dev/docs/catalog
Configure Catalog with various options including folder, Jinja environment, extensions, filters, tests, auto-reload, and asset resolver.
```python
catalog = Catalog(
folder="components/", # Optional initial folder
jinja_env=None, # Custom Jinja2 environment
extensions=None, # Extra Jinja2 extensions
filters=None, # Custom template filters
tests=None, # Custom template tests
auto_reload=True, # Auto-detect file changes
asset_resolver=None, # Asset URL resolver callback
**globals # Global template variables
)
```
--------------------------------
### Django Migration
Source: https://jx.scaletti.dev/docs/from-jinjax
Update Django integration by removing the JinjaX extension and simplifying catalog setup.
```python
# Before
import jinjax
env.add_extension(jinjax.JinjaX)
catalog = jinjax.Catalog(jinja_env=env)
catalog.add_folder("components")
# After
import jx
catalog = jx.Catalog("components", jinja_env=env)
```
--------------------------------
### Get component signature
Source: https://jx.scaletti.dev/docs/api/catalog
Returns metadata about a component, including arguments, slots, and associated CSS/JS files.
```python
get_signature(
relpath: str
) -> dict[str, typing.Any]
```
--------------------------------
### Access Flask Globals in Components
Source: https://jx.scaletti.dev/docs/working/flask
Example of using Flask template utilities within a Jx component.
```jinja
```
--------------------------------
### Importing Components from Prefixed Catalog Folders
Source: https://jx.scaletti.dev/docs/components
Shows how to import components when their catalog folder has been assigned a prefix.
```jinja
{#import "@ui/button.jinja" as Button #}
{#import "@ui/modal.jinja" as Modal #}
```
--------------------------------
### Initialize Jx Catalog
Source: https://jx.scaletti.dev/docs/from-jinjax
Initialize the Jx catalog using the new positional folder argument and keyword arguments for globals.
```python
catalog = jx.Catalog(
"components/", # optional folder shortcut (new)
site_name="My Site", # globals are now **kwargs, not a dict
)
```
--------------------------------
### Good Practice: Default Classes
Source: https://jx.scaletti.dev/docs/attrs
Illustrates the best practice of providing default classes to components using `attrs.render(class='btn')` to ensure base styling is always applied.
```jinja
{# ✅ Good - ensures base styling #}