0

I have a layout.html page with a <footer> that I want to display in almost all pages using {% extends "layout.html %}. Only in the user profile page the footer will be different. How can I do that?

2

jinja handles conditionals. One possible solution: Add a conditional in the <footer> block and send an indicator when the profile page is rendered. Sample html code:

<footer>

    {% if not f1 %}
        <p> default footer </p>

    {% else %}
        <p> alternate footer </p>

    {% endif %}

</footer>

Add the argument where necessary in application.py e.g.

return render_template("profile.html",f1="footer")

2
  • In the profile page, how would this indicator look like? I'm not finding anything about it. Oct 26 at 14:48
  • Answer has been clarified. Sorry for the imprecise language. Oct 26 at 18:36
1

DinoCoderSaurus did give a good answer, but you can do like this as well.

Add this to your layout.html.

{% block footer %}
    <p>Footer Content</p>
{% endblock %}

And for any page you don't want the footer just do this

{% block footer %}{% endblock %}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .