Skip to content

Commit

Permalink
Update index.mdx
Browse files Browse the repository at this point in the history
it would be good have a separate "components" folder for shared components and also have "components" subfolder at each django-app level.

Changes made based on feedback from  @SmileyChris  
#51 (comment)
  • Loading branch information
AhnafCodes authored and jpsca committed Apr 22, 2024
1 parent b999652 commit 7c8d4ee
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions docs/content/guide/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,24 @@ catalog = jinjax.Catalog(jinja_env=app.jinja_env)
```
**Django**:
(configure jinja in setting.py and [jinja_env.py](https://docs.djangoproject.com/en/5.0/topics/templates/#django.template.backends.jinja2.Jinja2))
To have a separate "components" folder for shared components and also have "components" subfolder at each django app level
```python
env.add_extension(JinjaX)
catalog = Catalog(jinja_env=env)
catalog.add_folder("components")
import jinjax
from jinja2.loaders import FileSystemLoader

def environment(loader: FileSystemLoader, **options):
env = Environment(loader=loader, **options)

...

env.add_extension(jinjax.JinjaX)
catalog = jinjax.Catalog(jinja_env=env)

catalog.add_folder("components")
for dir in loader.searchpath:
catalog.add_folder(os.path.join(dir, "components"))

return env
```

The ["do" extension](https://jinja.palletsprojects.com/en/3.0.x/extensions/#expression-statement) is enabled by default, so you can write things like:
Expand Down

0 comments on commit 7c8d4ee

Please sign in to comment.