Angel
2.x
2.x
  • Introduction
  • Migration from Angel 1.1.x
    • Rationale - Why a new Version?
    • Framework Changelog
    • 2.0.0 Migration Guide
  • ORM
    • About
    • Basic Functionality
    • Relations
    • Migrations
    • NoSQL
    • PostgreSQL
  • Guides
    • Getting Started
    • Basic Routing
    • Dependency Injection Patterns
    • Installation & Setup
    • Without the Boilerplate
    • Requests & Responses
    • Dependency Injection
    • Basic Routing
    • Request Lifecycle
    • Middleware
    • Controllers
    • Parsing Request Bodies
    • Using Plug-ins
    • Rendering Views
    • Service Basics
    • REST Client
    • Testing
    • Error Handling
    • Pattern Matching and Parameter
    • Command Line
    • Writing a Plugin
  • Example Projects
  • YouTube Tutorials
  • Ecosystem
  • Packages
    • Authentication
    • CORS
    • Database-Agnostic Relations
    • Configuration
    • Database Adapters
      • MongoDB
      • RethinkDB
      • JSON File-based
      • ORM
    • Front-end
      • Mustache Templates
      • Jael template engine
        • Github
        • Basics
        • Custom Elements
        • Strict Resolution
        • Directive: declare
        • Directive: for-each
        • Directive: extend
        • Directive: if
        • Directive: include
        • Directive: switch
      • compiled_mustache-based engine
      • html_builder-based engine
      • Markdown template engine
      • Using Angel with Angular
    • Hot Reloading
    • Pagination
    • Polling
    • Production Utilities
    • Reverse Proxy
    • Router
    • Serialization
    • Service Seeder
    • Static Files
    • Security
    • Server-sent Events
    • shelf Integration
    • Task Engine
    • User Agents
    • Validation
    • Websockets
Powered by GitBook
On this page
  • Rendering Views
  • Example
  • ViewGenerator
  • Next Up...
  1. Guides

Rendering Views

PreviousUsing Plug-insNextService Basics

Last updated 6 years ago

Rendering Views

Just like res.render in Express, Angel's ResponseContext exposes a Future called render. This invokes whichever function is assigned to your server's viewGenerator.

There is a Mustache templating plug-in for Angel available:

There is also , one of the few actively-developed HTML templating engines for Dart.

Angel support for Jael is provided through .

Another is Jinja2, which was recently ported by to Dart by .

Angel support for Jinja2 can be found here:

Example

app.get('/view', (req, res) async => await res.render('hello', {'locals': ['foo', 'bar']});

ViewGenerator

Angel declares the following typedef:

/// A function that asynchronously generates a view from the given path and data.
typedef Future<String> ViewGenerator(String path, [Map data]);

A templating plug-in can assign one of these to app.viewGenerator to set itself up:

import 'dart:io';
import 'package:angel_framework/angel_framework.dart';

Future<void> plugin(Angel app) async {
  app.viewGenerator = (String path, [Map data]) async {
    return "Requested view $path with locals: $data";
  };
}

main() async {
  var app = new Angel();
  await app.configure(plugin);
  await app.startServer();
}

Next Up...

Explore Angel's isomorphic .

Find out how to .

client library
test Angel applications
https://github.com/angel-dart/mustache
Jael
package:angel_jael
Olzhas Suleimen
https://pub.dartlang.org/packages/angel_jinja
Rendering Views
Example
ViewGenerator typedef
Next Up...