Last active
          January 1, 2016 17:09 
        
      - 
      
 - 
        
Save alexferl/8175403 to your computer and use it in GitHub Desktop.  
    Jinja2 macro for Twitter Bootstrap 3 alerts.
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | {% macro render_alert(category=None, dismissable=False, error=False, | |
| message=None, link=None) -%} | |
| {% if not category and not error %} | |
| {% set category = 'success' %} | |
| {% elif error %} | |
| {% set category = 'danger' %} | |
| {% endif %} | |
| <div class="alert alert-{{ category }} | |
| {% if dismissable %} alert-dismissable{% endif %}"> | |
| {% if dismissable %} | |
| <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button> | |
| {% endif %} | |
| {% if category == 'success' %} | |
| <strong>Yay!</strong> {{ message|safe }} | |
| {% elif category == 'danger' %} | |
| <strong>Uh-oh!</strong> {{ message|safe }} | |
| {% elif category == 'info' %} | |
| <strong>Heads-up!</strong> {{ message|safe }} | |
| {% elif category == 'warning' %} | |
| <strong>Not so fast!</strong> {{ message|safe }} | |
| {% endif %} | |
| {% if link %} | |
| <a href="{{ link.href }}" class="alert-link">{{ link.message|safe }}</a> | |
| {% endif %} | |
| </div> | |
| {%- endmacro %} | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
Use like this in your templates:
Import first:
Dismissable error message:
Undismissable warning message:
With a link:
and so on.