No description
Find a file
2024-12-06 09:45:23 +00:00
src Fixed issue parsing multiple loops 2024-12-06 09:00:19 +00:00
tests Removed test artifacts 2024-12-06 09:02:52 +00:00
.gitignore Updated nimble version (#3) 2024-12-06 09:45:23 +00:00
atlas.workspace Fixed issue parsing multiple loops 2024-12-06 09:00:19 +00:00
LICENSE.txt Added License 2024-01-23 18:19:24 +00:00
nim.cfg Fixed some stuff 2024-02-02 18:40:53 +00:00
README.md Fixed some stuff 2024-02-02 18:40:53 +00:00
templater.nimble Updated nimble version (#3) 2024-12-06 09:45:23 +00:00
TODO.md Fixed some stuff 2024-02-02 18:40:53 +00:00

Templater

A Nim-based HTML templating engine inspired by Python's Jinja.

Performs Compile-time template validation, to ensure you don't get any nasty surprises when running your code.

Docs

Installation

Global Installation:

nimble install templater

Local Installation:

atlas init
atlas use templater

Usage

Load from Template String

import templater

const myTemplate = """
<!DOCTYPE html>
<html>
    <head>
        <title>{{pageTitle}}</title>
    </head>

    <body>
        <h1>{{myHeader}}</h1>
        <ul>{{#for item in items | index}}
            <li>{{#index}}: {{#item}}</li>
        {{#endfor}}</ul>
    </body>
</html>
"""

let vars = newVarTable(("pageTitle", newVariable("My Page Title")), ("myHeader", newVariable("Page Header")), ("items", newVariable(@[newVariable("Item 0"), newVariable("Item 1")])))

let renderedTemplate = loadTemplate(myTemplate, vars)

Load from a Template file

let vars = newVarTable(("pageTitle", newVariable("My Page Title")), ("myHeader", newVariable("Page Header")), ("items", newVariable(@[newVariable("Item 0"), newVariable("Item 1")])))

let renderedTemplate = loadTemplateFile(staticRead("template.html"), vars)

Template Syntax

Variables:

<!DOCTYPE html>
<html>
    <head>
        <title>{{pageTitle}}</title>
    </head>

    <body>
        <h1>{{welcomeMessage}}</h1>
   </body>
</html>

Lists:

<!DOCTYPE html>
<html>
    <head>
        <title>My Page</title>
    </head>

    <body>
        <li>
            {{#for item in items}}
            <li>{{#item}}</li>
            {{#endfor}}
        </li>

        <li>
            {{#for item in items | index}} <!--index here is optional, and can be named anything-->
            <li>{{#index}}: {{#item}}</li>
            {{#endfor}}
        </li>
   </body>
</html>