-
-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Trying to find a way to override the title of flash message with custom message #14
Comments
Seems like it is not supported as of now |
Just need this minor change message = Template('''
{% with messages = get_flashed_messages(with_categories=true) %}
{% if messages %}
<script type="text/javascript">
(function($) {
$(document).ready(function() {
{{ toastr_options }}
{% for category, message in messages %}
{% if category is undefined or category == 'message' %}
toastr.info(\'{{ message | replace("'","\\\\'") }}\', \'{{ category|capitalize }}\')
{% elif category and category not in ['message', 'error', 'warning', 'info', 'success'] %}
toastr.info(\'{{ message | replace("'","\\\\'") }}\', \'{{ category|capitalize }}\')
{% else %}
toastr.{{ category }}(\'{{ message | replace("'","\\\\'") }}\', \'{{ category|capitalize }}\')
{% endif %}
{% endfor %}
});
})(jQuery);
</script>
{% endif %}
{% endwith %}
''') And to invoke flash("All OK","test header") |
Hi, @Shivam0609 Thanks for the interest in You are right, for now,
This way all messages will be categorized as I was thinking about: flash({'title': "Custom Title", 'message': "All OK"}, 'success') And check if is a mapping: {% with messages = get_flashed_messages(with_categories=true) %}
{% if messages %}
<script type="text/javascript">
(function($) {
$(document).ready(function() {
{{ toastr_options }}
{% for category, message in messages %}
{% if category is undefined or category == 'message' %}
{% set category = 'info' %}
{% endif %}
{% if message is mapping %}
toastr.{{ category }}(\'{{ message['message'] | replace("'","\\\\'") }}\', \'{{ message['title'] | replace("'","\\\\'") }}\')
{% else %}
toastr.{{ category }}(\'{{ message | replace("'","\\\\'") }}\', \'{{ category|capitalize }}\')
{% endif %}
{% endfor %}
});
})(jQuery);
</script>
{% endif %}
{% endwith %} |
Above solutions looks Fine to me aswell and is more general |
Hi @wiltonsr , Hope to get this implemented soon, That will be Great. Thanks |
Version 0.5.8 already available. I used your solution and mine, so you could use: @app.route('/')
def index():
flash("Message", 'Custom Title') # Will be info category by default
flash({'title': "Custom Title", 'message': "Info Category"}) # Will also be info category by default
flash({'title': "Custom Title", 'message': "Error Message"}, 'error') # Or use dict syntax to pass a custom category
return render_template('index.html') |
Current Behaviour :
Getting category displayed on flash message like Info, Success, Warning, Message etc..
Required Behaviour :
Instead of Category want to see a Custom message as below.
If their is some configuration paramter to do that please confirm ?
The text was updated successfully, but these errors were encountered: