Help for web.app.render_template
Sample CLI
gway web.app render-template
Full Code
def render_template(*, title="GWAY", content="", css_files=None, js_files=None):
global _ver
version = _ver = _ver or gw.version()
# --- MAIN: THEME CSS HANDLING ---
theme_css = None
if is_enabled('web.nav'):
try:
theme_css = gw.web.nav.get_style()
except Exception:
theme_css = "/static/styles/base.css"
css_files = gw.to_list(css_files)
if theme_css and theme_css not in css_files:
idx = 1 if css_files and 'global.css' in css_files[0] else 0
css_files.insert(idx, theme_css)
css_links = ""
if css_files:
for href in css_files:
css_links += f'<link rel="stylesheet" href="{href}">\n'
js_files = gw.to_list(js_files)
js_links = ""
if js_files:
for src in js_files:
js_links += f'<script src="{src}"></script>\n'
favicon = f'<link rel="icon" href="/favicon.ico" type="image/x-icon" />'
credits = f'''
<p>GWAY is written in <a href="https://www.python.org/">Python 3.11</a>.
Hosting by <a href="https://www.gelectriic.com/">Gelectriic Solutions</a>,
<a href="https://pypi.org">PyPI</a> and <a href="https://github.com/arthexis/gway">Github</a>.</p>
'''
nav = ""
if is_enabled('web.nav'):
nav = gw.web.nav.render(homes=_homes)
html = template("""<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>{{!title}}</title>
{{!css_links}}
{{!favicon}}
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head>
<body>
<div class="page-wrap">
<div class="layout">
{{!nav}}<main>{{!content}}</main>
</div>
<footer><p>This website was <strong>built</strong>, <strong>tested</strong>
and <strong>released</strong> with <a href="https://arthexis.com">GWAY</a>
<a href="https://pypi.org/project/gway/{{!version}}/">v{{!version}}</a>.</p>
{{!credits}}
</footer>
</div>
{{!js_links}}
</body>
</html>
""", **locals())
return html