{{ if isAdmin }}
Admin
{{ elseif user }}
User
{{ else }}
Guest
{{ endif }}
Loops
CodeBlockhtml
{{ for item in items }}
- {{ item.name }}
{{ endfor }}
{{ for i=0; i
Flash: {{ session('message') }}
{{ if hasSession('message') }}...{{ endif }}
Flash Sessions in Views
Use response flash helpers to pass one-time messages to the next rendered view. In the route/controller, call withSuccess() or withError() and redirect:
CodeBlockdart
app.post('/settings', (Context ctx) async {
final data = await ctx.req.validate({'name': 'required|string|min:2'});
// ... save settings
return ctx.res
?.withSuccess('Settings updated successfully.')
.back(fallback: '/settings');
});
Then in your template, read them with session() and guard with hasSession():
CodeBlockhtml
{{ if hasSession('success') }}
{{ session('success') }}
{{ endif }}
{{ if hasSession('error') }}
{{ session('error') }}
{{ endif }}