I'm not familiar with revel
, but message "flashing" is typically used when you need some user communication to carry over through a redirect. The godoc seems to describe it as exactly for that use case as well.
If you're rendering a template directly in this request handler, you probably shouldn't be using c.Flash
. My guess of what is happening is that revel
will only show the flash message received with the request. Calling c.Flash.Error
sets the field in the cookie, which means it will be sent back to the caller, not to the template. On the next render, it will read from the cookie that the caller sends back to the server, which would include this flash message. Apparently, though, setting a new flash message replaces the old one, causing it to (yet again) send it to the caller not the template.
The good news is that there's really only one way for your message to get on the page, and you can almost definitely shoehorn your message there: the template data! Instead of calling c.Flash.Error
, send the message using the usual mechanisms. In this case, assuming your flash.html
template contains something like:
{{ if .flash.error }}
<div class="error">{{ .flash.error }}</div>
{{ end }}
you should be able to pass that data by replacing the c.Flash.Error("Message")
line with:
c.ViewArgs["flash"] = map[string]string{"error": "Message"}