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> <!doctype html>
<html lang="{% block lang %}de{% endblock %}"> <html lang="{% block lang %}de{% endblock %}">
<head> <head>
......
...@@ -5,10 +5,16 @@ ...@@ -5,10 +5,16 @@
{% endblock title %} {% endblock title %}
{%- block content -%} {%- block content -%}
<div class="container"> <div class="container">
<img id="image" src="{{ url_for('instance.static', <img
filename=schild.image) if schild.image else 'placeholder' }}" /> 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"> <p id="text">
{{ schild.text|default("Inhalt") }} {{ schild.text|default(lipsum(n=1, min=5, max=10)) }}
</p> </p>
</div> </div>
{% endblock content %} {% endblock content %}
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
{%- block content -%} {%- block content -%}
<div> <div>
<p id="text"> <p id="text">
{{ schild.text|default("Inhalt") }} {{ schild.text|default(lipsum(n=2, min=5, max=10)) }}
</p> </p>
</div> </div>
{% endblock content %} {% endblock content %}
...@@ -2,7 +2,6 @@ from . import db ...@@ -2,7 +2,6 @@ from . import db
from .models import Schild from .models import Schild
from .helpers import Blueprint, get_template_attribute from .helpers import Blueprint, get_template_attribute
import textwrap
from flask import url_for from flask import url_for
...@@ -31,13 +30,8 @@ def schild_pdf(ident): ...@@ -31,13 +30,8 @@ def schild_pdf(ident):
@bp.route("/sample/<template>.html") @bp.route("/sample/<template>.html")
def sample_html(template): def sample_html(template):
lipsum = textwrap.dedent(""" return bp.render_template(template)
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")
)
@bp.route("/sample/<template>.pdf") @bp.route("/sample/<template>.pdf")
def sample_pdf(template): 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