Last active
November 22, 2016 10:15
-
-
Save n0mad01/801398e55d58da5c281626461066adba to your computer and use it in GitHub Desktop.
Simple Bootstrap Alert Slim/Twig Macro
This file contains 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
/** | |
* 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'); |
This file contains 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
{# Usage of the Bootstrap Alert Twig Macro in a Template #} | |
{% import "notices.phtml" as notices %} | |
{{notices.bootstrap_alert(messages)}} |
This file contains 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
{# 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