src/happyx/tmpl_engine/engine

Search:
Group by:

Template Engine 🎴

Provides templates render with nimja library

Usage ❔

templateFolder("/public/templates")

proc renderIndex(name: string): string =
  renderTemplate("index.html")

serve "127.0.0.1", 5000:
  get "/":
    return renderIndex("Ethosa")

Procs

proc render(model: auto; htmlTemplate: static[string]): string
This proc renders htmlTemplate file in templates folder.
Note: See also templateFolder procedure. This macro setup template folder

Example

main.nim:

type
  Cat = object
    name: string

var cat = Cat(name: "Baron")
cat.render("profile.html")

templates/profile.html:

<!DOCTYPE html><html>
<head>
  <title>{{ model.name }}</title>
</head>
<body></body>
</html>

Macros

macro renderTemplate(name: static[string]): untyped
Renders template from file
macro templateFolder(f: string)
Specifies templates folder