Closed acobster closed 3 years ago
A workable implementation of this exists in WSHS in the Alert\DismissableAlert class.
Alert\DismissableAlert
I should be able to set an alert in the Timber context:
$context['global_alert'] = new DismissableAlert($message, [ 'cookies' => $_COOKIE, ]);
Then consume it like this in Twig:
{% if global_alert and not global_alert.dismissed %} <script> window.addEventListener('DOMContentLoaded', function() { var bar = document.querySelector('.site-alert'), closeBtn = bar.querySelector('.site-alert__close'); closeBtn.addEventListener('click', function(e) { e.preventDefault(); // hide the alert bar bar.style.display = 'none'; // persist the dismissal in a cookie document.cookie = closeBtn.dataset.alertCookie; }); }); </script> <div class="site-alert"> <div class="site-alert__wrapper container"> <div class="site-alert__text rtecontent"> {{ global_alert.message }} <a href="#" data-alert-cookie="{{ global_alert.cookie_text }}" class="site-alert__close">{{ source('img/icons/icon-close.svg') }}<span class="screen-reader-text">Close</span></a> </div> </div> </div> {% endif %}
It ain't work like that.
A workable implementation of this exists in WSHS in the
Alert\DismissableAlert
class.Expected behavior
I should be able to set an alert in the Timber context:
Then consume it like this in Twig:
Actual behavior
It ain't work like that.
TODO