Comment by embedding-shape
5 days ago
> just do some string-replacement targeted at a narrow use-case instead of using a complicated templating engine.
A neat little in-between "string replacements" and "flown blown templating" is doing something like what hiccup introduced, basically using built-in data structures as the template. Hiccup looks something like this:
(h/html [:span {:class "foo"} "bar"])
And you get both the power of templates, something easier than "templating engine" and with the extra benefit of being able to use your normal programming language functions to build the "templates".
I also implemented something similar myself (called niccup) that also does the whole "data to html" shebang but with Nix and only built-in Nix types. So for my own website/blog, I basically do things like this:
nav = [ "nav"
[ "h2" "Posts" ]
[ "ul" (map (p: [ "li" [ "a" { href = "${p.slug}.html"; } p.title ] ]) posts) ]
]
And it's all "native" Nix, but "compiles" to HTML at build-time, great for static websites :)
No comments yet
Contribute on Hacker News ↗