I use Flask-Login which provides the current_user
object in templates. I want to write a macro to show a comment form or a log in link depending on if the user is l
According to jinja2 docs not every variable is available in jinja2 macros. Change your macro and send ’current_user’ as a parameter to it:
% macro comment_form(form, current_user, disabled=False) %}
{% if current_user.is_authenticated() %}
{{ quick_form(form) }}
{% else %}
You are not signed in. Please Sign In With Github to continue
{% endif %}
{% endmacro %}
and this is how your will use it:
{% from "macros/comments.html" import comment_form %}
{% extends "base.html" %}
{% block content %}
{# ... content goes here ... #}
{{ comment_form(form, current_user) }}
{% endblock %}