-1

I would like to reuse the following code several times:

body.html file

<div class="container-fluid">
    <div class="row">
        <div class="col-md-2 text-dark">
            ...
            <p>Download: <a href="{{ link }}" class="link-secondary">link</a></p>
        </div>
        <div class="col-md-10">
            <iframe src="{{ link }}" style="min-height:88vh;width:100%"></iframe>
        </div>
    </div>
</div>

In the sfa.html file I want to use body.html file and passing the the following argument: "{{url_for('static', filename='pdf/Lorem-Ipsum.pdf')}}"

sfa.html

<!DOCTYPE html>
<html>
<head>

{% include 'header.html'%} //works fine

</head>
<body>

{% include 'nav.html'%} //works fine

{% include 'body.html' with 'link' : "{{url_for('static', filename='pdf/Lorem-Ipsum.pdf')}}" %} //here is the problem

</body>
</html>

I am getting the following error in the browser: jinja2.exceptions.TemplateSyntaxError: expected token 'end of statement block', got 'with'

What is the problem with my code?

mano98
  • 1

1 Answers1

-1

In your case, i think you'll have to do something like this :

{% with link="{{url_for('static', filename='pdf/Lorem-Ipsum.pdf')}}" %}
  {% include "body.html" %}
{% endwith %}

Documentation

Other thread about this

FahRine
  • 36
  • 1
  • Is your flask server set to serve static files and your pdf at {flask_app_folder}/static/pdf/Lorem-Ipsum.pdf ? – FahRine Dec 17 '22 at 20:43
  • Yes, the pdf location is the following: {flask_app_folder}/static/pdf/Lorem-Ipsum.pdf – mano98 Dec 17 '22 at 20:44