Skip to content

Instantly share code, notes, and snippets.

@j
Created November 26, 2011 22:20
Show Gist options
  • Save j/1396401 to your computer and use it in GitHub Desktop.
Save j/1396401 to your computer and use it in GitHub Desktop.
Ads the ability to use translations with or without variables in flash messages
# ...
####################
## Flash Messages ##
####################
flash.user.recover.password.already.requested: |
Oops %username%! We see that you've already requested a password within the last 24 hours. Check your email to reset it!
flash.notice.this.works.yay: "This flash system works, yay!"
# ...
<?php
[...]
$session->setFlash('error', array('flash.user.recover.password.already.requested', array('%username%' => $user->getUsername())));
$session->setFlash('notice', 'flash.notice.this.works.yay');
[...]
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Some Title</title>
</head>
<body>
{# start flash messages #}
{% for key, flash in app.session.getFlashes() %}
<div class="flash-message {{ key }}">
{{ flash[0]|default(flash) | trans(flash[1]|default({})) | raw }}
</div>
{% endfor %}
{# end flash messages #}
<div id="content">
{% block content '' %}
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment