Skip to content
Snippets Groups Projects
Commit 3425dbe3 authored by Thomas Schneider's avatar Thomas Schneider
Browse files

instance, examples/templates: Better defaults handling

A Schild template should be able to be invoked without more context/variables
than Flask and Jinja2 already provide.

This also slightly moves the image path handling.
parent c24abcb7
No related branches found
No related tags found
No related merge requests found
{%- set schild = schild | default(None) -%}
<!doctype html>
<html lang="{% block lang %}de{% endblock %}">
<head>
......
......@@ -5,10 +5,16 @@
{% endblock title %}
{%- block content -%}
<div class="container">
<img id="image" src="{{ url_for('instance.static',
filename=schild.image) if schild.image else 'placeholder' }}" />
<img
id="image"
{% if schild.image -%}
src="{{ url_for('instance.static', filename='img/'+schild.image) }}"
{%- else -%}
src="{{ url_for('instance.static', filename='img/sample.png') }}"
{%- endif -%}
/>
<p id="text">
{{ schild.text|default("Inhalt") }}
{{ schild.text|default(lipsum(n=1, min=5, max=10)) }}
</p>
</div>
{% endblock content %}
......@@ -6,7 +6,7 @@
{%- block content -%}
<div>
<p id="text">
{{ schild.text|default("Inhalt") }}
{{ schild.text|default(lipsum(n=2, min=5, max=10)) }}
</p>
</div>
{% endblock content %}
......@@ -2,7 +2,6 @@ from . import db
from .models import Schild
from .helpers import Blueprint, get_template_attribute
import textwrap
from flask import url_for
......@@ -31,13 +30,8 @@ def schild_pdf(ident):
@bp.route("/sample/<template>.html")
def sample_html(template):
lipsum = textwrap.dedent("""
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.
""")
return bp.render_template(
template, schild=dict(title="Überschrift", text=lipsum, image="sample.png")
)
return bp.render_template(template)
@bp.route("/sample/<template>.pdf")
def sample_pdf(template):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment