Home

Awesome

The RedHttp project is no longer maintained. See Carter for a similar low-ceremony experience.

Ecs Renderer for RedHttpServer

A simple templating engine extension for Red

GitHub Nuget Nuget Dependent repos (via libraries.io)

Usage

After installing and referencing this library, the Red.Response has the extension method RenderPage(pageFilePath, parameters, ..).

The pageFilePath must be the path of a .ecs file.

The .ecs file format

The .ecs file format is an extension used for html pages with ecs-tags.

Tags

Example

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Status page</title>
</head>
<body>
    <b>Uptime in minutes: <% uptime %></b></br>
    <b>Version: <% version %></b>
</body>
</html>
server.Get("/statuspage", async (req, res) =>
{
    await res.RenderPage("pages/statuspage.ecs", new RenderParams
    {
        { "uptime", DateTime.UtcNow.Subtract(startTime).TotalMinutes },
        { "version", RedHttpServer.Version }
    });
});

Could result in:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Status page</title>
</head>
<body>
    <b>Uptime in minutes: 42</b></br>
    <b>Version: 3.0.0</b>
</body>
</html>

The file extension is enforced to avoid confusion with regular html files without tags.

The format is somewhat inspired by the ejs format, though you cannot embed JavaScript, or C# for that matter, in the pages.

Embed your dynamic content using RenderParams instead of embedding the code for generation of the content in the html.