Browse Source

Keep flashed message examples in one place.

pull/341/merge
Ron DuPlain 13 years ago
parent
commit
c93ea5551c
  1. 23
      docs/patterns/flashing.rst
  2. 25
      flask/helpers.py

23
docs/patterns/flashing.rst

@ -129,14 +129,15 @@ render each category in a separate block.
.. sourcecode:: html+jinja .. sourcecode:: html+jinja
{% with errors = get_flashed_messages(category_filter=["error"]) %} {% with errors = get_flashed_messages(category_filter=["error"]) %}
{% if errors %} {% if errors %}
<div class="errors"> <div class="alert-message block-message error">
<ul> <a class="close" href="#">×</a>
{% for message in messages %} <ul>
<li class="error">{{ message }}</li> {%- for msg in errors %}
{% endfor %} <li>{{ msg }}</li>
</ul> {% endfor -%}
</div> </ul>
{% endif %} </div>
{% endwith %} {% endif %}
{% endwith %}

25
flask/helpers.py

@ -281,30 +281,7 @@ def get_flashed_messages(with_categories=False, category_filter=[]):
* `category_filter` filters the messages down to only those matching the * `category_filter` filters the messages down to only those matching the
provided categories. provided categories.
Example usage: See :ref:`message-flashing-pattern` for examples.
.. sourcecode:: html+jinja
{% for category, msg in get_flashed_messages(with_categories=true) %}
<p class=flash-{{ category }}>{{ msg }}
{% endfor %}
Example usage similar to http://twitter.github.com/bootstrap/#alerts:
.. sourcecode:: html+jinja
{% with errors = get_flashed_messages(category_filter=["error"]) %}
{% if errors %}
<div class="alert-message block-message error">
<a class="close" href="#">×</a>
<ul>
{%- for msg in errors %}
<li>{{ msg }}</li>
{% endfor -%}
</ul>
</div>
{% endif %}
{% endwith %}
.. versionchanged:: 0.3 .. versionchanged:: 0.3
`with_categories` parameter added. `with_categories` parameter added.

Loading…
Cancel
Save