F
Flint DartDocs
GitHub

Views

Views are stored in lib/views. Render them using ctx.res.view():

CodeBlock dart
app.get('/', (Context ctx) async {
  return ctx.res.view('home', data: {
    'title': 'Flint Docs'
  });
});

A view file named lib/views/home.flint.html can extend a layout:

CodeBlock html
{{ extends('layouts.app') }}

{{ section('content') }}

# {{ title }}

{{ endsection }}

Layouts live under lib/views/layouts and use {{ yield('content') }}.

Template Processors

Flint’s view engine supports these built‑in template features:

  • extends — layout inheritance
  • section / yield — slot content into layouts
  • include — partials
  • variables{{ ... }} interpolation
  • if_statementif/endif
  • for_loopfor/endfor
  • switch_casesswitch/case/default
  • comment — template comments
  • assets — asset helper tags
  • session — session/error helpers in templates

Quick Examples

CodeBlock html
{{ if user }}

Welcome, {{ user.name }}

{{ endif }}

  {{ for item in items }}

- {{ item }}

  {{ endfor }}

{{ include('partials.nav') }}

Layouts: extends + section + yield

CodeBlock html
{{ extends('layouts.app') }}

{{ section('title', 'Home') }}

{{ section('content') }}

# Hello, {{ user.name }}

{{ endsection }}

In your layout, render sections with {{ yield('content') }}. You can also use {{ section('sidebar') }}...{{ show }} for defaults.

Includes With Data

CodeBlock html
{{ include('partials.card', { "title": "Hello", "body": "..." }) }}

Conditionals

CodeBlock html
{{ if isAdmin }}

Admin

{{ elseif user }}

User

{{ else }}

Guest

{{ endif }}

Loops

CodeBlock html
{{ 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:

CodeBlock dart
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():

CodeBlock html
{{ if hasSession('success') }}

{{ session('success') }}

{{ endif }}

{{ if hasSession('error') }}

{{ session('error') }}

{{ endif }}
F
Flint DartBackend framework and Dart UI docs

Build routes, controllers, APIs, docs, and browser UI from one Dart-shaped stack.

Controllers
OpenAPI
Flint UI
Copyright 2024 Flint Dart. Maintained by Eulogia Technologies.
v 1.1.14
MIT License
Built with Dart