Jinja theme capability
Project description
Fastapi Jinja theming system.
Include Block Tag
This template system heavily uses the include_block tag. This tag will include an html file as a block. This tag can be overridden with an html file matching the name or by a block tag matching the base name.
Create a base for your theme
{# theme_templates/theme/base.html #}
<html>
<body>
{% include_block "theme/sidenav.html" %}
{% block contents %}
<h1>Hello World!</h1>
{% endblock %}
</body>
</html>
Normal navigation for your theme
{# theme_templates/theme/sidenav.html #}
<ul>
<li><a href="/">Home</a></li>
<li><a href="/page1">Page 1</a></li>
<li><a href="/page2">Page 2</a></li>
</ul>
Override with block
Override navigation by using a block. The block name will be the same as the base html filename. Note: different templates directory
{# templates/main.html #}
{% extends "theme/base.html" %}
{% block sidenav %}
<ul>
<li>Hello</li>
</ul>
{% endblock sidenav %}
Override with HTML file
Alternatively you can override by using an html file. Note: different templates directory
{# templates/theme/sidenav.html #}
<ul>
<li><a href="/">Home</a></li>
<li><a href="/link">Link to my other site</a></li>
</ul>
Fastapi using the templates
from fastapi import FastAPI, Request
from justengel_theme import ThemeTemplates
MYD_DIR = os.path.dirname(__file__)
# Search for project files first
project_dir = os.path.join(MY_DIR, 'templates')
templates = ThemeTemplates(project_dir)
# Search for theme files if project files are not found
theme_dir = os.path.join(MY_DIR, 'theme_templates')
templates.add_directory(theme_dir)
app = FastAPI()
@app.get('/')
def index(request: Request):
return material.TemplateResponse('main.html', {'request': request})
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
justengel_theme-0.0.4.tar.gz
(8.5 kB
view hashes)
Built Distribution
Close
Hashes for justengel_theme-0.0.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c4e2e8364f54f0c355e5b4771710ad069f628522094fcd32ca3fda7402726469 |
|
MD5 | 6ae77bb157d9edc22d6b1fb26d369e69 |
|
BLAKE2b-256 | 815ed8f464a214c1dea77c5e3ba460f709bab0dd4d306fc0c2ebaf5969a94605 |