Skip to content

Instantly share code, notes, and snippets.

@n0mad01
Last active November 22, 2016 10:15
Show Gist options
  • Save n0mad01/801398e55d58da5c281626461066adba to your computer and use it in GitHub Desktop.
Save n0mad01/801398e55d58da5c281626461066adba to your computer and use it in GitHub Desktop.
Simple Bootstrap Alert Slim/Twig Macro
/**
* Using PHP Slim Frameworks slim/flash
* https://www.slimframework.com/docs/features/flash.html
*
* Assuming this is called from within a Slim route $app->get()
*/
$this->flash->addMessage('success', 'Some success message');
{# Usage of the Bootstrap Alert Twig Macro in a Template #}
{% import "notices.phtml" as notices %}
{{notices.bootstrap_alert(messages)}}
{# notices.phtml #}
{% macro bootstrap_alert(messages) %}
{% if messages %}
{% for notice_level, notices in messages %}
<div class="alert alert-{{ notice_level }}">
<a class="close" data-dismiss="alert" href="#">x</a>
{% for notice in notices %}
<p>{{ notice }}</p>
{% endfor %}
</div>
{% endfor %}
{% endif %}
{% endmacro %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment