Skip to content

Commit

Permalink
Replace make-widget command by Page.make_import() method
Browse files Browse the repository at this point in the history
  • Loading branch information
Clément committed Jul 23, 2024
1 parent e3f8b10 commit ab1daca
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 378 deletions.
26 changes: 18 additions & 8 deletions EXAMPLES.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,26 @@ And finally we can use this blocks with :
```

# Exemple for automatic widget inclusion
Let's assume we have 3 macros widgets : `navbar()` in `widgets/menu.html`, `header()` and `footer()` in `widgets/page.html`.

First you can verify that all widgets are found with the `listwidget` command.\
Then the `makewidget` command will create a file `content/templates/<engine>/allwidgets.html`, that groups all the widgets found, and is automatically imported as `widgets` in all pages.\
First you can verify that all widgets are found with the `listwidget` command :
```shell
$ ./manage.py list-widgets
0 django widget found

The line `{% import 'allwidgets.html' as widgets %}` is added at the beginning of each `Body` section of pages.

For instance, if we have 3 widgets : `navbar.html`, `header.html` and `footer.html` we can use them in pages :
content/templates/jinja2/widgets/menu.html
navbar()
content/templates/jinja2/widgets/page.html
footer()
header()
2 jinja2 widget files found (3 macros)
```
All the listed widgets are automatically imported in all pages and can be accessed by : `<filename>.<macroname>()`\
The lines `{% import '<widget-file-path>' as <widget-file-name> %}` is added at the beginning of each `Body` section of pages.

We can use our widgets in pages with :
```jinja
{{ widgets.navbar(...) }}
{{ widgets.header(...) }}
{{ widgets.footer(...) }}
{{ menu.navbar(...) }}
{{ page.header(...) }}
{{ page.footer(...) }}
```
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,6 @@ For each command, the option `-h` give u some help.

`./manage.py list-widgets` to list all widgets found in content directories

`./manage.py make-widgets` to make a file that groups all jinja2 widgets macros for easier includes. It is automatically called by `runserver` and `distill-local` commands. \
See an example in `EXAMPLE.md`

## Others

JFM-Engine is a friendly fork of [JSSG](https://github.com/jtremesay/jssg/) made in agreement with the JSSG developer because of different goals. \
Expand Down
301 changes: 0 additions & 301 deletions content/templates/jinja2/allwidgets.html

This file was deleted.

Loading

0 comments on commit ab1daca

Please sign in to comment.