Skip to main content
Module

x/fastro/docs/rendering.md

Fast and simple web application framework for deno
Go to Latest
File

Template Rendering

  • fastro init command will generate folders and files like this.

    webapp
    ├── Dockerfile
    ├── middleware
    │   └── support.ts
    ├── public
    │   ├── favicon.ico
    │   ├── index.html
    │   └── logo.svg
    └── services
        ├── hello.controller.ts
        └── hello.template.html
    
    3 directories, 7 files

    You can render html template and pass dynamic value on it.

  • Open hello.template.html in services folder

    <html>
        <head>
            <title>${greeting} ${name}</title>
        </head>
        <body>
            ${greeting} ${name}
        </body>
    </html>

    You can change hello name with other.

  • Open hello.controller.ts handler.

    Uncomment request.view and comment request.send.

    import type { Request } from "https://raw.fastro.dev/master/mod.ts";
    export const handler = (request: Request) => {
      request.view("hello.template.html", { greeting: "Hello", name: "World" });
      // request.send("hello");
    };
    
  • Open url

    http://localhost:3000/hello

    Now you see the greeting and name on the browser.

What’s next: