{# templates/mdl/page_sections/snackbar.html.twig #}
{% with { flashes: app.flashes } %}
{% set snakbarArgs = [] %}
{% for label, messages in flashes %}
{% for message in messages %}
{% set snakbarArgs = snakbarArgs|merge(['{ label: `' ~ label ~ '`, message: `' ~ message ~ '` }']) %}
{% endfor %}
{% endfor %}
{% set snakbarArgs = snakbarArgs|join(',') %}
<div id="app-snackbar" class="mdl-js-snackbar mdl-snackbar">
<div class="mdl-snackbar__text"></div>
<button class="mdl-snackbar__action" type="button"></button>
</div>
<script>
(function() {
const snackbarContainer = document.getElementById(`app-snackbar`);
const showAppSnackbar = (args = {}) => {
const data = {
label: args.label || `!info`,
message: args.message || `!message`,
timeout: args.timeout || 2000,
actionHandler: args.actionHandler || ( () => {alert(`!actionHandler`)} ),
actionText: args.actionText || `!actionText`
};
snackbarContainer.MaterialSnackbar.showSnackbar(data);
};
setTimeout(() => {
[ {{ snakbarArgs }} ].forEach( args => showAppSnackbar(args));
}, 2000);
}());
</script>
{% endwith %}